Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [solved] Driver not loaded QMYSQL
Forum Updated to NodeBB v4.3 + New Features

[solved] Driver not loaded QMYSQL

Scheduled Pinned Locked Moved Installation and Deployment
2 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fscibilia
    wrote on last edited by
    #1

    Hi all,

    I'm getting crazy with QMYSQL :(. I want to connet to a mysql server through this code (for testing the connection only). Qt version is 5.2.1, while OS is Ubuntu 13.10.

    @
    #include <QCoreApplication>

    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlError>

    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    qDebug() << "Started";
    qDebug() << "library path " << a.libraryPaths();

    QSqlDatabase db;
    db.addDatabase("QMYSQL");
    qDebug() << db.drivers();
    qDebug() << "available = " << db.isDriverAvailable("QMYSQL");
    qDebug() << "db error=" &lt;&lt; db.lastError().databaseText();
    qDebug() &lt;&lt; "driver error=" &lt;&lt; db.lastError().driverText();
    db.setHostName("127.0.0.1");
    db.setPort(3306);
    db.setUserName("root");
    db.setPassword("mysql");
    db.setDatabaseName("test");
    bool done = db.open();
    qDebug() << "done=" &lt;&lt; done;
    
    if (! done)
    {
        qDebug() &lt;&lt; "Failed to open database";
        qDebug() << " - db error=" &lt;&lt; db.lastError().databaseText();
        qDebug() &lt;&lt; " - driver error=" &lt;&lt; db.lastError().driverText();
    }
    qDebug() &lt;&lt; "Terminating";
    
    return a.exec&#40;&#41;;
    

    }
    @

    I get the following output:

    Started
    library path ("/home/fabio/Qt/5.2.1/gcc/plugins", "/home/fabio/Tests/Qt/build-TestDatabase-Desktop_Qt_5_2_1_GCC_32bit-Debug")
    ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
    available = true
    db error= "Driver not loaded"
    driver error= "Driver not loaded"
    done= false
    Failed to open database

    • db error= "Driver not loaded"
    • driver error= "Driver not loaded"
      Terminating

    As you can see, driver is not loaded, even if all libs are at the correct places and dependencies are satisfied.

    This is the past of the plugin dependencies
    fabio@ubuntu:~$ ldd /home/fabio/Qt/5.2.1/gcc/plugins/sqldrivers/libqsqlmysql.so
    linux-gate.so.1 => (0xb77de000)
    libmysqlclient.so.18 => /usr/lib/i386-linux-gnu/libmysqlclient.so.18 (0xb7492000)
    libQt5Sql.so.5 => /home/fabio/Qt/5.2.1/gcc/lib/libQt5Sql.so.5 (0xb7453000)
    libQt5Core.so.5 => /home/fabio/Qt/5.2.1/gcc/lib/libQt5Core.so.5 (0xb6f89000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb6ea0000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6cec000)
    libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb6cd2000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6ccd000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6cb1000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6c6e000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6c51000)
    libicui18n.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicui18n.so.51 (0xb6a2f000)
    libicuuc.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicuuc.so.51 (0xb68b6000)
    libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0xb68b2000)
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb68a9000)
    libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb67a5000)
    /lib/ld-linux.so.2 (0xb77df000)
    libicudata.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicudata.so.51 (0xb525c000)
    libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb521a000)

    and, in the turn, the pasting of libmysqlclient which the plugin depends on:

    fabio@ubuntu:~$ ldd /usr/lib/i386-linux-gnu/libmysqlclient.so.18
    linux-gate.so.1 => (0xb773a000)
    libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb73e6000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb73e1000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb73c5000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7382000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7365000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb71b1000)
    /lib/ld-linux.so.2 (0xb773b000)

    To be more precise, I have built the plugin directly from source code (5.2.1) and the database mentioned in the code really exists on 127.0.0.1.

    I also tried with QMYSQL3 (same result).

    I really don't know what else to check.
    Please help me

    Thanks in advance
    Fabio

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fscibilia
      wrote on last edited by
      #2

      Solved,

      addDatabase is a static function and then correct way to create an instance of database is the following:

      @
      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      @

      Sorry for the wasted time.

      Fabio

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved