Results 1 to 5 of 5

Thread: My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

  1. #1
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

    OS: Linux-FC6
    Mysql:mysql-standard-5.0.21
    QT:Qt version 4.2.2
    mysql plugin:/usr/lib64/qt4/plugins/sqldrivers/libqsqlmysql.so



    GDataBaseConnecter code:

    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QSqlQuery>
    #include <QtGlobal>
    #include <QtPlugin>

    class GDataBaseConnecter
    {
    Q_IMPORT_PLUGIN(qsqlmysql)
    private:
    QSqlDatabase gdb;

    public:
    GDataBaseConnecter();
    bool connectToDataBase();
    bool disconnectToDataBase();
    QString runSelect();
    bool runInsert();
    };

    GDataBaseConnecter::GDataBaseConnecter()
    {
    printf("this is gzq start.\n");
    gdb.addDatabase("QMYSQL");
    gdb.setHostName("fengtianwe");
    gdb.setDatabaseName("qtbase");
    gdb.setUserName("root");
    gdb.setPassword("root");
    printf("this is gzq over.\n");
    }

    bool GDataBaseConnecter::connectToDataBase()
    {
    printf("this is connect start.\n");
    if(gdb.open())
    {
    printf("Open OK.\n");
    }
    else
    {
    printf("Open Cut.\n");
    printf("This is Error : %s\n",gdb.lastError().text().toLatin1().data());
    }
    printf("this is connect over.\n");
    }

    ---------------------------------
    main code:

    #include <QApplication>
    #include "GDataBaseConnecter.h"

    int main( int argc, char ** argv )
    {
    QApplication app( argc, argv );
    printf("App is start.\n");
    GDataBaseConnecter gdbc;
    gdbc.connectToDataBase();
    //return app.exec();
    return 0;
    }
    ---------------------------------

    when I called the GDataBaseConnecter::connectToDataBase(),then console output:

    This is Error : Driver not loaded Driver not loaded


    why ?? why ?? why ??

    may i shoud use the mysql 4.x?

  2. #2
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

    and the "qDebug() << QSqlDatabase::drivers();" code will output:
    ("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QPSQL7", "QPSQL")

    and I programing uesd MonkeyStudio IDE

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

    Quote Originally Posted by fengtian.we View Post
    OS: Linux-FC6
    Mysql:mysql-standard-5.0.21
    QT:Qt version 4.2.2
    mysql plugin:/usr/lib64/qt4/plugins/sqldrivers/libqsqlmysql.so

    GDataBaseConnecter::GDataBaseConnecter()
    {
    printf("this is gzq start.\n");
    gdb.addDatabase("QMYSQL");
    gdb.setHostName("fengtianwe");
    gdb.setDatabaseName("qtbase");
    gdb.setUserName("root");
    gdb.setPassword("root");
    printf("this is gzq over.\n");
    }
    gdb.setUserName("root");
    gdb.setPassword("root");
    gdb.open(); /* open here !!! */
    printf("this is gzq over.\n");

    if (gdb..isOpen()) { /* or !gdb..isOpen()*/

    }


    and put connection name to better debug!

    QStringList QSqlDatabase::connectionNames () [static]

    I connect on 2 db lan & web on same time to send update query on 2° server ....

    Qt Code:
    1. /* typedef QMap<QString, QString> Appsetting; Appsetting OneVar; from xml config tagname/value */
    2.  
    3. qDebug() << "### use 2 connection lan & web " << usedb2;
    4.  
    5. db_0 = QSqlDatabase::addDatabase("QMYSQL",QString("LanConnection_%1").arg(connectnr)); /* QMYSQL */
    6. db_0.setHostName(OneVar["dbhost1"]);
    7. db_0.setDatabaseName(OneVar["dbbase1"]);
    8. db_0.setUserName(OneVar["dbuser1"]);
    9. db_0.setPassword(OneVar["dbpass1"]); /* OneVar["LIMITSQL"] */
    10. db_0.open();
    11.  
    12. if (db_0.isOpen()) {
    13. cnn1 = true;
    14. tableslist_0 = db_0.tables();
    15. counttable_0 = tableslist_0.size();
    16. qDebug() << "### table count primo " << tableslist_0.size();
    17. } else {
    18. cnn1 = false;
    19. QMessageBox::warning(this, tr( "Message from %1" ).arg(_PROGRAM_NAME_),
    20. (tr("Unable to connect on server base %1")
    21. .arg(OneVar["dbhost1"])));
    22. return;
    23. }
    24. cnn2 = false;
    25. if (usedb2) {
    26. db_1 = QSqlDatabase::addDatabase("QMYSQL",QString("WebConnection_%1").arg(connectnr)); /* QMYSQL */
    27. db_1.setHostName(OneVar["dbhost2"]);
    28. db_1.setDatabaseName(OneVar["dbbase2"]);
    29. db_1.setUserName(OneVar["dbuser2"]);
    30. db_1.setPassword(OneVar["dbpass2"]); /* OneVar["LIMITSQL"] */
    31. db_1.open();
    32.  
    33. if (db_1.isOpen()) {
    34.  
    35. tableslist_1 = db_1.tables();
    36. //////////////////////////// qDebug() << "### table count secondo " << tableslist_1.size();
    37. cnn2 = true;
    38. } else {
    39. QMessageBox::warning(this, tr( "Message from %1" ).arg(_PROGRAM_NAME_),
    40. (tr("Unable to connect on server web %1")
    41. .arg(OneVar["dbhost2"])));
    42. return;
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

    Quote Originally Posted by fengtian.we View Post
    GDataBaseConnecter::GDataBaseConnecter()
    {
    printf("this is gzq start.\n");
    gdb.addDatabase("QMYSQL");
    gdb.setHostName("fengtianwe");
    gdb.setDatabaseName("qtbase");
    gdb.setUserName("root");
    gdb.setPassword("root");
    printf("this is gzq over.\n");
    }
    Try:
    Qt Code:
    1. GDataBaseConnecter::GDataBaseConnecter()
    2. {
    3. printf("this is gzq start.\n");
    4. gdb = QSqlDatabase::addDatabase("QMYSQL");
    5. gdb.setHostName("fengtianwe");
    6. gdb.setDatabaseName("qtbase");
    7. gdb.setUserName("root");
    8. gdb.setPassword("root");
    9. printf("this is gzq over.\n");
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)

    Oh God!! thanks my friend!!

    I got it! :

    I do :
    gdb.addDatabase("QMYSQL");

    but the return value not get. so no driver loaded

    shoud be this:
    gdb=QSqlDatabase::addDatabase("QMYSQL");

    ok,I get connect to mysql!!!!

Similar Threads

  1. QSqlDatabase: QMYSQL driver not loaded
    By onder in forum Newbie
    Replies: 12
    Last Post: 29th March 2017, 15:43
  2. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  3. qodbc driver not loaded error in release mode
    By mandal in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2006, 10:42
  4. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 14:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.