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");
        db.setHostName("localhost");
        db.setUserName("root");
        db.setPassword("");
        db.setDatabaseName("testdb");
        if (db.open()) {
            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 (mysqlquery.next()){
                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;
            }
        }
        else{
    
    
        }
        return a.exec();
    }
    

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

    Any ideas?


  • Moderators

    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 )


  • Moderators

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

    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSql
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlDatabase
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlDriver
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlDriverCreator
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlDriverCreatorBase
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlDriverPlugin
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlError
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlField
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlIndex
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlQuery
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlQueryModel
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlRecord
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlRelation
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlRelationalDelegate
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlRelationalTableModel
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlResult
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QSqlTableModel
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QtSql
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QtSqlDepends
    /usr/include/x86_64-linux-gnu/qt5/QtSql/QtSqlVersion

    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 !
    Thanks.


  • Moderators

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.