Results 1 to 3 of 3

Thread: Using mysql database

  1. #1
    Join Date
    Aug 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Using mysql database

    I am new to Qt and am trying to use the mysql database on a windows installation. I have already spent too much time and can't sort it out.

    I have QTPLUGIN += qsqlmysql and QT += sql in the .pro file. When I load the project I get a message. two of them that it is redundant. It isn't any better when I leave the line out. I checked in the plugin directory and it is there.

    I also have the -llibmysql entry added to the LIBS's path
    win32:CONFIG(release, debug|release): LIBS += -L"C:/Program Files/MariaDB 10.1/lib/" -llibmysql

    The application seems to build correctly.

    my database access is copied from somewhere:
    Qt Code:
    1. bool createConnection()
    2. {
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    4. db.setHostName("localhost");
    5. db.setDatabaseName("testdb");
    6. db.setUserName("root");
    7. db.setPassword("rmsipw");
    8. if (!db.open()) {
    9. qDebug() << "Database error occurred";
    10. return false;
    11. }
    12. return true;
    13. }
    To copy to clipboard, switch view to plain text mode 

    when it runs I get:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3
    Database error occurred
    Not Connected:

    Edit:
    It is way more complicated then this: My application wants to compile with an old version of mingw on my machine. Even though the default kit is Desktop Qt 5.7.0 MSVC2013 64bit is the default Kit?
    Last edited by raymadigan; 23rd August 2016 at 22:34.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using mysql database

    You should not need the LIBS entry, but you will need the Mysql client library (part of MariaDB/MySql) in the PATH or the same folder as the executable so Windows can find it when Qt tries to load the Qt plugin. The file is named something like libmysql.dll.

  3. #3
    Join Date
    Aug 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using mysql database

    Thanks for your help. I remove the lib entry. I really should have spent a little more time, I solved the problem and will make the thread solved. I used the QT_DEBUG_PLUGINS=1 and found out the real problem was it was using the wrong toolchain. Once I got past that issue it works great.

Similar Threads

  1. Linking Qt with Database MySql
    By SumitVaise in forum Newbie
    Replies: 2
    Last Post: 3rd August 2015, 22:13
  2. How to Connect to MySQL database
    By johnL in forum Newbie
    Replies: 12
    Last Post: 16th May 2015, 17:43
  3. Qt and MySQL database
    By Stanfillirenfro in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2013, 08:58
  4. Cannot connect to mysql database
    By phapha in forum Newbie
    Replies: 3
    Last Post: 27th October 2011, 15:58
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 13:48

Tags for this Thread

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.