Results 1 to 4 of 4

Thread: QSqlDatabase: QMYSQL driver not loaded

  1. #1
    Join Date
    May 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlDatabase: QMYSQL driver not loaded

    After several days of trying to make a connection to my MYSQL database work I am almost giving up, so could someone please HELP!

    I am using Qt4.2 and MySql server version 5.0.83 in Ubuntu Karmic Koala. My header file has these includes:
    #include <QSqlDatabase>
    #include <qsqldatabase.h>
    #include <QSqlError>
    #include <QSqlQuery>
    #include <QtSql>
    #include <QMYSQLDriver>
    #include <QtSql/QMYSQLDriver>

    The connection code is:

    static bool createConnection()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("xxx");
    db.setUserName("xxx");
    db.setPassword("xxxx");

    QSqlDatabase::database( "connection-test" );
    db.open();

    if (!db.open()) {
    QMessageBox::critical(0, QObject::tr("Database Error"),
    db.lastError().text());

    return false;
    }

    QSqlQuery query;
    query.exec("select xxx from yyy");


    return true;
    }

    And what I get is a message called Database Error saying: Driver not loaded Driver not loaded

    The Application Output is:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QSQLITE2 QPSQL7 QPSQL

    Could someone please tell me what needs to be done ????

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSqlDatabase: QMYSQL driver not loaded

    Quote Originally Posted by lise View Post
    After several days of trying to make a connection to my MYSQL database work I am almost giving up, so could someone please HELP!
    Let's try to get this working

    I am using Qt4.2 and MySql server version 5.0.83 in Ubuntu Karmic Koala. My header file has these includes:
    Qt Code:
    1. #include <QSqlDatabase>
    2. #include <qsqldatabase.h>
    3. #include <QSqlError>
    4. #include <QSqlQuery>
    5. #include <QtSql>
    6. #include <QMYSQLDriver>
    7. #include <QtSql/QMYSQLDriver>
    To copy to clipboard, switch view to plain text mode 
    You only need #include <QtSql> because this will include all the others you mention

    The connection code is:
    Qt Code:
    1. QSqlDatabase::database( "connection-test" );
    To copy to clipboard, switch view to plain text mode 
    You can delete this line, it doesn't do what you want or think it does. It returns the database with the name "connection-test", it does not set the connection name.

    And what I get is a message called Database Error saying: Driver not loaded Driver not loaded

    The Application Output is:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QSQLITE2 QPSQL7 QPSQL
    It tells you exactly what is wrong. The Qt MySql driver is not found.
    You will need to build the driver and install it in the correct plug-in folder of your Qt installation.
    Or, try your package manager to see if you can just download it.

  3. The following user says thank you to tbscope for this useful post:

    lise (1st June 2010)

  4. #3
    Join Date
    May 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlDatabase: QMYSQL driver not loaded

    You will need to build the driver and install it in the correct plug-in folder of your Qt installation.
    [/QUOTE]

    My problem is I am very new to Qt. I think I have the driver for MySql, QMYSQLDRIVER, but my suspicion is that it is not placed where the program searches for it. Is there a standard or a rule that says which is the correct plug-in forlder?

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSqlDatabase: QMYSQL driver not loaded

    Yes, read the following website carefully:
    http://doc.qt.nokia.com/4.6/sql-driver.html

Similar Threads

  1. QSqlDatabase: QMYSQL driver not loaded
    By onder in forum Newbie
    Replies: 12
    Last Post: 29th March 2017, 15:43
  2. QSqlDatabase: QMYSQL driver not loaded
    By earthling in forum Qt Programming
    Replies: 13
    Last Post: 4th December 2010, 16:19
  3. QMYSQL driver not loaded
    By akhila in forum Newbie
    Replies: 1
    Last Post: 22nd February 2010, 19:24
  4. Replies: 6
    Last Post: 28th April 2009, 07:58
  5. The strange problem:"QSqlDatabase: QMYSQL driver not loaded"
    By osmanthus in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd January 2009, 16:12

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.