Important: Please read the Qt Code of Conduct -

Error: "Qtsql/Qtsql: No such file or directory"

  • I already looked up the older previous posting on this , but none worked.
    I tested a new QT console App for MySQL connector C on Windows 7.
    It worked fine.
    I redid the same on Ubuntu 16.04 MySQL Server version: 5.7.17 with a new linux 32 bit library, but got the compile error:
    " Qtsql/Qtsql: No such file or directory."
    ( I only used the 1 OS and unchecked options for each different OS )
    The pro file was relinked as shown:

    QT += core
    QT += sql
    QT -= gui
    TARGET = testdb
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    unix:!macx: LIBS += -L$$PWD/../MySQl/mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/lib/ -lmysql
    INCLUDEPATH += $$PWD/../MySQl/mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include
    DEPENDPATH += $$PWD/../MySQl/mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include

    The main.cpp file:

    #include <QCoreApplication>
    #include <Qtsql/Qtsql>
    #include <Qtsql/QSqlDatabase>
    #include <Qtsql/QSqlQuery>
    #include <iostream>
    using namespace std;
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        // create database connection
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        if ( {
            cout << "Database connected" << endl;
        else {
            cout << "Database connect failed" << endl;
        string userid, username, userstate, userphone;
        QSqlQuery mysqlquery;
        mysqlquery.exec("SELECT * FROM student");
        if (mysqlquery.size() > 0) {
            while ({
                userid = mysqlquery.value("id").toString().toUtf8().constData();
                username = mysqlquery.value("name").toString().toUtf8().constData();
                userstate = mysqlquery.value("state").toString().toUtf8().constData();
                userphone = mysqlquery.value("phone").toString().toUtf8().constData();
                cout << userid <<" - "<< username <<" - "<< userstate <<" - "<< userphone<< endl;
        return a.exec();

    I tried both the Mysql connector C & C++, same result.

    Any ideas?

  • Hi! Did you install Qt via the online installer, the offline installer or through Ubuntu's package manager?

  • I do not remember.
    I did not see it in the Ubuntu package manager, so I think it was an apt-get install.
    The Help is Qt Creator 3.5.1 Based on Qt5.5.1 (GCC 5.2.1 20151129, 32 bit )

  • Looking at the list of contents of Ubuntu's package qtbase5-dev:


    So I assume it's just typos in your includes. Try to change them to:

    #include <QtSql/QtSql>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlQuery>

  • This post is deleted!

  • That was it.
    Must have been a typo !

  • Great :-) Please use the topic tools to mark the thread as solved (see Hitchhiker's Visual Guide to the Qt Forum for help).

Log in to reply