Results 1 to 13 of 13

Thread: How to Connect to MySQL database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to Connect to MySQL database

    I am trying to connect to a MySQL database but QT doesn't load the MySQL Driver.
    Both QSqlDatabase::drivers().contains("QMYSQL") and QSqlDatabase::isDriverAvailable("QMYSQL") return true but

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL") fails with error message

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

    The API documentation for addDatabase() implies that the addDatabase("DRIVER") call will open a connection and therefore should load the necessary driver.
    Certainly QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE") succesfully opens a connection to SQLITE without any supplementary calls to "Load" a driver.

    Some someone please explain how to get a connection to MySQL? or Load the MySQL driver?

    Note: MySQL Server version: 5.5.37-0ubuntu0.14.04.1 is installed and running. Database can be accessed from Terminal so problem is not on MySQL side.

    Regards
    johnL

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Connect to MySQL database

    Try setting QT_DEBUG_PLUGINS=1 in the environment from where you run the program.

    Maybe that gives more hints on what is going wrong when Qt attempts to load the plugin.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Connect to MySQL database

    Probably libmysqlclient.dll/so is not accesible by the plugin.

  4. #4
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to Connect to MySQL database

    Check this thread.

  5. #5
    Join Date
    Jun 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to Connect to MySQL database

    OK - I've set QT_DEBUG_PLUGINS=1 in /etc/environment
    Now what - does this initiate logging? If so, what file in what location?

    I've spent most of today investigating this and implementing various "solutions" from other trails in the forum - installing mysql-connector, adding symlinks to libmysqlconn, copying libmysqlclient_r.so etc - to no avail

    A log printout may well identify the problem.

    Regards

  6. #6
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to Connect to MySQL database

    Have you installed libmysqlclient-dev?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Connect to MySQL database

    Quote Originally Posted by johnL View Post
    Now what - does this initiate logging? If so, what file in what location?
    Not to a file, to the applications STDERR if I remember correctly.

    Cheers,
    _

  8. #8
    Join Date
    May 2013
    Location
    Sofia, Bulgaria
    Posts
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to Connect to MySQL database

    One possible problem can be that the version of installed MySQL is 64-bit, while the version of Qt (and QMYSQL plugin) is 32-bit.

Similar Threads

  1. Replies: 5
    Last Post: 27th January 2014, 22:22
  2. Function to connect to a MySQL database
    By graciano in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2013, 16:36
  3. Cannot connect to mysql database
    By phapha in forum Newbie
    Replies: 3
    Last Post: 27th October 2011, 14:58
  4. How to connect Qt with MYSQL??
    By Gokulnathvc in forum Newbie
    Replies: 10
    Last Post: 24th March 2011, 00:52
  5. Mysql unknown database, QMYSQL unable to connect
    By lixo1 in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 21:39

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.