Results 1 to 8 of 8

Thread: getting MySQL to work with Qt

  1. #1
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question getting MySQL to work with Qt

    Hi,

    I have been trying to get Qt to work with MySQL without any luck. When I run a 2 line test code, it comes back with a message saying- "This application has failed to start because LIBMYSQL.DLL was not found. Re-installing the application may fix this problem". Can anyone please guide me on fixing the issue and getting MySQL to work with Qt?

    Here's what I have done so far-

    1) I downloaded and installed MySQL 5.1.34 using the installer( mysql-5.1.34-win32.msi) from MySQL website.
    2) I downloaded the latest opensource Qt sources(qt-win-opensource-src-4.5.1) from Qt website and configured it as follows:
    a) added the path to locate qmake etc.
    b). configure -debug-and-release -l libmysql -I D:\MySQL\MySQLServer5.1\include -L D:\MySQL\MySQLServer5.1\lib\opt -qt-sql-mysql -qt-sql-odbc
    c) nmake

    These steps went fine but when I run the test code, it doesn't work. The code that I was trying to run is :
    ------
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSqlDatabase>
    3. #include <QStringList>
    4. #include <QtDebug>
    5.  
    6. int main( int argc, char **argv )
    7. {
    8. QCoreApplication app( argc, argv );
    9. qDebug() << QSqlDatabase::drivers();
    10. }
    To copy to clipboard, switch view to plain text mode 

    ------

    Can anyone please help me fix the issues here?

    Thanks,
    Ashish
    Last edited by wysota; 14th May 2009 at 01:14.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: getting MySQL to work with Qt

    Where did you place the MySQL dll? It should be in a folder that is in your system search path (i.e. C:\Windows\system32) so that the system dynamic linker can find it. You can also place it alongside your application binary as its directory is also searched by the linker.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: getting MySQL to work with Qt

    Hi Wysota,

    Thanks for replying.

    Are you talking about libmysql.dll? I cannot find any file by the name MYSQL.dll.

    I did not place the 'libmysql.dll' anywhere, they are presently located in the MySql installation folder at "../MySQL/MySQLServer5.1/bin", "../MySQL/MySQLServer5.1/lib/debug" and "../MySQL/MySQLServer5.1/lib/opt"

    Is there any other step that I need to do after the (1) Qt configure step as per my previous post and (2) nmake?

    Thanks,
    Ashish

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: getting MySQL to work with Qt

    They have to be accessible by the compiler and linker. Try placing the library in C:\Windows\System32 and see if it helps.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: getting MySQL to work with Qt

    Thanks Wysota. I placed the DLL library in my application directory and it works now.

    The code from my first post works and gives me the following result:

    ("QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QSQLITE")
    Press any key to continue . . .

    However when I add a few more lines to my code to open a test database it doesn't work. Here is the new code:
    -----
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSqlDatabase>
    3. #include <QStringList>
    4. #include <QtDebug>
    5. #include <QPushButton>
    6. #include <QApplication>
    7. #include <QSqlError>
    8. #include <QSqlQuery>
    9.  
    10. #include <iostream>
    11. using namespace std;
    12. int main( int argc, char **argv )
    13. {
    14.  
    15. QCoreApplication app( argc, argv );
    16. qDebug() << QSqlDatabase::drivers();
    17.  
    18. QSqlDatabase *mydb = new QSqlDatabase();
    19. mydb->addDatabase("QMYSQL");
    20. mydb->setHostName("w.x.y.z"); //number changed
    21. mydb->setPort(zzzz); //number changed
    22. mydb->setDatabaseName("test");
    23. mydb->setUserName("tmp");
    24. mydb->setPassword("tmp123");
    25. bool ok = mydb->open();
    26. qDebug()<<mydb->lastError();
    27. cout<<"ok="<<ok<<endl;
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 
    ------

    And here's the output of the above code:

    ("QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QSQLITE")
    QSqlError(-1, "Driver not loaded", "Driver not loaded")
    ok=0
    Press any key to continue . . .

    Can you please guide me on resolving the issue here? What am I doing wrong here?

    Thanks,
    Ashish
    Last edited by wysota; 15th May 2009 at 16:57. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: getting MySQL to work with Qt

    QSqlDatabase::addDatabase() is a static method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: getting MySQL to work with Qt

    I've downloaded Qt 4.5.1 Opensource, Installed it (with mingw) and built mysql plugin according to Qt Centre's Wiki. Then I ran my app and I also get "Driver not loaded". Can someone help me here since I do not know what to do anymore ....
    Qt 5.3 Opensource & Creator 3.1.2

  8. #8
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: getting MySQL to work with Qt

    I have a similar problem. I have built the PSQL driver and now it is the system's search path. But my application doesn't find this driver.
    I'm a rebel in the S.D.G.

Similar Threads

  1. Accessing xampp mysql database
    By synack in forum Newbie
    Replies: 8
    Last Post: 19th March 2009, 09:08
  2. Qt 4.4.0 + MinGW + MySQL installation problem
    By jambrek in forum Installation and Deployment
    Replies: 2
    Last Post: 1st December 2008, 11:02
  3. MySql and Qt 4.3 don't work together
    By john_crichton in forum Newbie
    Replies: 2
    Last Post: 9th May 2008, 11:57
  4. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 13:45
  5. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23

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.