Wednesday, September 21, 2011

Install Qt MYSQL Driver for Linux (Ubuntu).

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QSQLITE2

You might have come across this error, if you are using Qt SDK from Nokia.

Now follow these steps to get MYSQL working with Qt Creator.

Go to System-> Administration-> Synaptic manager and search "libqt4-sql-mysql" (libqt3-sql-mysql if you are using Qt3) and install the library by right clicking and select Mark for installation.



Now, in your Qt code add this line
                                qDebug() << QCoreApplication::libraryPaths();

You will see something like this upon running your program.
("/home/raja/QtSDK/Desktop/Qt/473/gcc/plugins", "/home/raja/Documents/QtProjects/SyncTest-build-desktop")

Now copy libqsqlmysql.so (search it or find it as shown in the above picture) to the above path. You can also use the library by using QCoreApplication::addLibraryPath(QString path).

7 comments:

  1. Thanks raja for the solution it worked for me!!!!!

    Thanks a lot :)

    ReplyDelete
  2. Happy that I helped Avinash! :-)

    ReplyDelete
  3. the second half (since my installation didn't come from synaptic) of this tutorial finished my hours-long battle with this problem in just few clicks.
    Many thanks!

    ReplyDelete
  4. Really smart using the qDebug! As Mikolaj said, your help finished my hours long battle in a few clicks. It was so simple and smart that, at first, I hardly believed it would work! Well done indeed! Many thanks!!!

    ReplyDelete
  5. I have the same error, but, I don't want with QtCreator, only I need deploy my application, so, I need install the MySQL driver only to Qt, not by QtCreator.

    What I must to do?

    ReplyDelete
  6. not solve

    "QSQLITE"
    "QMYSQL"
    "QMYSQL3"
    "QPSQL"
    "QPSQL7"
    ("/home/prashant/Qt5.5.0/5.5/gcc/plugins", "/home/prashant/qms/build-qms-Desktop_Qt_5_5_0_GCC_32bit-Debug")
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    Failed to connect to root mysql admin

    ReplyDelete

Your Ad Here