Results 1 to 14 of 14

Thread: MySql Driver not loaded

  1. #1
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default MySql Driver not loaded

    Hey all

    I have a problem with mysql connection. When i try to connect to a mysql database i get the error "driver not loaded".

    I use the following code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3. #include <QSqlDatabase>
    4. #include <QSqlError>
    5. #include <QMessageBox>
    6.  
    7. bool createConnection()
    8. {
    9. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    10. db.setHostName("***********");
    11. db.setPort(3306);
    12. db.setDatabaseName("wachtrij");
    13. db.setUserName("root");
    14. db.setPassword("");
    15. if (!db.open()) {
    16. QMessageBox::critical(0, QObject::tr("Database Error"),
    17. db.lastError().text());
    18. return false;
    19. }
    20. return true;
    21. }
    22.  
    23.  
    24. int main(int argc, char *argv[])
    25. {
    26. QApplication app(argc, argv);
    27. QLabel *label = new QLabel;
    28. if(createConnection() != false)
    29. {
    30. label->setText("Database connected");
    31. }
    32. else
    33. {
    34. label->setText("Database failed to connect");
    35. }
    36. label->show();
    37. return app.exec();
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 

    I had a problem with compiling the code but that is solved.
    I followed these instructions: http://wiki.qtcentre.org/index.php?t...ws_using_MinGW
    and when i want to compile i ad QT += sql to the .pro file

    I've searched trough this forum and other forums but couldn't find the solution.

    I am using Qt 4.3 and mingw on windows xp

    I hope you can help me.

  2. #2
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    I tried solving it by importing the plugin i did that the following way:

    Configured with the following code:
    configure -release -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"
    Qt Code:
    1. #include <QtPlugin>
    2.  
    3. Q_IMPORT_PLUGIN(qsqlmysql)
    To copy to clipboard, switch view to plain text mode 

    To the code

    Made the .pro file with:
    qmake -project "QT += sql" "QTPLUGIN += qsqlmysql"

    And the when i run make i get the following error:
    Qt Code:
    1. mingw32-make -f Makefile.Release
    2. mingw32-make[1]: Entering directory `C:/Qt/4.3.0/Projects/hello'
    3. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
    4. oc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o "release\hello.exe" tmp\obj\re
    5. lease_shared\hello.o -L"c:\Qt\4.3.0\lib" -L"c:\Qt\4.3.0\lib" -lmingw32 -lqtmain
    6. -lQtSql4 -lQtGui4 -lQtCore4 -LC:/Qt/4.3.0/plugins/sqldrivers/ -lqsqlmysql4 -LC:
    7. \MySql\lib
    8. tmp\obj\release_shared\hello.o(.text+0x859):hello.cpp: undefined reference to `q
    9. t_plugin_instance_qsqlmysql()'
    10. collect2: ld returned 1 exit status
    11. mingw32-make[1]: *** [release\hello.exe] Error 1
    12. mingw32-make[1]: Leaving directory `C:/Qt/4.3.0/Projects/hello'
    13. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: MySql Driver not loaded

    Quote Originally Posted by eekhoorn12 View Post
    And the when i run make i get the following error:
    You need static plugins to make it work that way.

    Does sqlbrowser demo see the QMYSQL driver? Check with Dependency Walker whether the plugin can find MySQL DLLs (if not you will have to copy them to the same directory where your executable is).

  4. #4
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    I just reinstalled Mysql and Qt

    Mysql to c:\mysql and qt to the default directory

    After that i followed again the instructions from http://wiki.qtcentre.org/index.php?t...ws_using_MinGW

    After that i configured Qt with the command

    configure -static -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"

    When that was done i tried the sqldriver demo but it only showed QSQLITE and QODBC

    Then i tried -shared -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"

    I got the same results.

    I used dependency walker to check qsqlmysql4.dll from C:\Qt\4.3.0\plugins\sqldrivers and he got find al the dependency's except MPR.DLL

  5. #5
    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: MySql Driver not loaded

    You might try clearing the plugin cache --- maybe there's some stale data in it.

  6. #6
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    I cleared the plugin cache and then did the same thing as my previous post and still i get the same results.

  7. #7
    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: MySql Driver not loaded

    Quote Originally Posted by eekhoorn12 View Post
    I cleared the plugin cache and then did the same thing as my previous post and still i get the same results.
    Copy libmysql.dll to %QTDIR%\demos\sqlbrowser\release, start the Qt Command Prompt (there's a link in Start menu) and invoke:
    cd demos\sqlbrowser\release
    sqlbrowser.exe
    Can you see QMYSQL plugin in the "Driver" combo box?

  8. #8
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    No still just qsqlite and qodbc

  9. #9
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySql Driver not loaded

    try building it static first:
    -qt-sql-mysql -I"C:\mysql\include"
    and make sure the libmysql.a is present in "C:\Qt\4.3\lib"

    if you get compiler errors you can't resolve please post

  10. #10
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    Ok i removed all the programs again. Cleaned my register. Reinstalled Mysql and Qt.

    After that i followed the following instructions: http://wiki.qtcentre.org/index.php?t...ws_using_MinGW

    When i finished that i configured the program with
    Qt Code:
    1. configure -qt-sql-mysql -I "C:\mysql\include"
    To copy to clipboard, switch view to plain text mode 

    I watched it pass by al de .pro files and noticed that it didn't make the mysql.pro file.

    Qt Code:
    1. Reading C:/Qt/4.3.0/src/plugins/imageformats/tiff/tiff.pro
    2. Reading C:/Qt/4.3.0/src/plugins/sqldrivers/sqldrivers.pro
    3. Reading C:/Qt/4.3.0/src/plugins/sqldrivers/sqlite/sqlite.pro
    4. Reading C:/Qt/4.3.0/src/plugins/iconengines/iconengines.pro
    To copy to clipboard, switch view to plain text mode 

    Also i didn't place a libmysql.a in the C:\Qt\4.3.0\lib folder but a liblibmysql.a

    I tried de sqlbrowser demo and it didn't show mysql and i tried an example script and when i ran it i got the error message driver not loaded

    I hope i did everything correct.
    Last edited by eekhoorn12; 14th June 2007 at 00:36.

  11. #11
    Join Date
    Jun 2007
    Posts
    3
    Thanked 1 Time in 1 Post
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MySql Driver not loaded

    I have had the same problem and I have found a solution.
    with mysql-5.0.41 I was able to compile the plugin for qt, but it just wasn't being loaded. I reverted back to an older version of mysql, in my case, 5.0.27 and everything worked fine.

    This may or may not be the problem that you are having, but it is worth a try.

  12. #12
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    Quote Originally Posted by bongobonga View Post
    I have had the same problem and I have found a solution.
    with mysql-5.0.41 I was able to compile the plugin for qt, but it just wasn't being loaded. I reverted back to an older version of mysql, in my case, 5.0.27 and everything worked fine.

    This may or may not be the problem that you are having, but it is worth a try.
    And how did you configure evrything?

  13. #13
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySql Driver not loaded

    Maybe 2 other things you should check( if you haven't done for so far):

    After you configured Qt you get a report which contains the configuration, make sure mysql is yes (or plugin).

    Make sure your .pro file contains the line QT += sql

  14. #14
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySql Driver not loaded

    If you mean with the report the info get after you verify you want to configure qt the yes it always says that mysql: yes or mysqll: plugin

    And when i compile a project i always follow the same three steps.
    First: qmake -project "QT += sql"
    Second: qmake projectname.pro
    Third: make

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. My Mysql 5 and Qt 4.2.2 Problem (Driver not loaded)
    By fengtian.we in forum Qt Programming
    Replies: 4
    Last Post: 9th February 2007, 09:11
  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.