1

Operating System: win7 compiler : mingw4.8(come with Qt5.2) link to : Fedora core release 5, kernel 2.6.15-1.2054_FC5 smp on an i686

    db = new QSqlDatabase();
    db->addDatabase("QMYSQL");
    db->setHostName("localhost");
    db->setDatabaseName("myclinic");
    db->setUserName("root");
    db->setPassword(",trth12");  

    qDebug() << loader.errorString();
    qDebug() << "drivers: "<< QSqlDatabase::drivers();

    if (db->open())
        qDebug() << "Success!";
    else
        qDebug() << db->lastError().text();

messages

QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL 7 “The shared library was not found.” drivers: (“QSQLITE”, “QMYSQL”, “QMYSQL3”, “QODBC”, “QODBC3”, “QPSQL”, “QPSQL7”)

“Driver not loaded Driver not loaded”

László Papp
  • 51,870
  • 39
  • 111
  • 135
user3172211
  • 51
  • 1
  • 5
  • Possible duplicate of [qt5.1.1 mysql ubuntu QMYSQL driver not loaded](http://stackoverflow.com/questions/21476529/qt5-1-1-mysql-ubuntu-qmysql-driver-not-loaded) – Smar Oct 04 '16 at 09:19
  • @Smar this is more a windows one. Have one for that (url I can dupe hammer to) ? I did close the prior one you did today – Drew Oct 04 '16 at 16:17
  • @Drew Okay looks like I spent far too little time reading this... The first sentence talks about Windows which is linked to Fedora, the error this gives is more or less same. Tags do not contain either OS, is there a convention that OS specific question should have `windows` tag? Also should question description be modified? As is, I’d want to vote this as unclear too... – Smar Oct 05 '16 at 07:13
  • @Smar well sometimes it is just necessary to read it a few times mostly we don't worry about the tags too much. Most questions come from people with low rep that don't know tagging. So the whole thing is nebulous half the time and we just do the best we can – Drew Oct 05 '16 at 13:23

3 Answers3

2

You seem to be either missing the mysql plugin on your Windows or the proper mysql installation itself in which case you will need to get that done by installing all the necessary mysql libraries on your system where the plugin QtSql driver can recognize it.

The plugin should be available under the plugins/sqldrivers folder as a dll. You could also put it into an sqldrivers folder beside your application, so somethiing like this:

- yourapplication.exe
- sqldrivers/qsqlmysql4.dll

You would need to grab it somehow, or build it yourself. This is the explanation from the documentation how to do so:

How to Build the QMYSQL Plugin on Windows

You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):

cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
nmake

If you are not using a Microsoft compiler, replace nmake with make in the line above.

There is another problem with your code though. You should be using "127.0.0.1" instead of "localhost" for mysql databases.

Community
  • 1
  • 1
László Papp
  • 51,870
  • 39
  • 111
  • 135
0

Thanks for the answer, but the problem is not because I lack the qsqlmysql.dll but I don't have the libmysql.dll(looks like this dll do not come with win7).

Here is a video which show you how to install mysql

user3172211
  • 51
  • 1
  • 5
  • 1
    Your question was lacking basic information apparently. I expected mysql would be installed if you want to use mysql. :) Either way, I updated my reply respectively... – László Papp Jan 11 '14 at 08:08
  • Thanks for your sincerity, I though the mysql plugin of Qt5.2 is enough for this task(sorry for my ignorant) – user3172211 Jan 25 '14 at 15:54
0

I had the same Pb of you

Solution is:

The Qt MySQL drivers is already inside Qt5 (but not in the previous version!)

You just need the "libmysql.dll" next to your app exe (or in windows directory!) You find "libmysql.dll" in "mysql\mysqlX.X.XX\lib\opt" directory.

If Qt MySQL driver not found the libmysql.dll the error is the same as the driver is not found...

Good chance for the next!