QtCreator:How to write MySQl IncludePath on *.pro file?



  • I'm Japanese student.
    And now, I'm tring to connect MySQL server.

    I use Windows7 64bit, Qt 4.8.3(32bit) Qt Creator2.6.1 MySQL 5.5.29.
    Qt creator use minGW.

    So, I tryed write ↓ to "*.pro" files.
    INCLUDEPATH += C:\Program Files\MySQL\MySQL Server 5.5\include

    And I tryed build.
    Thisu is the error message.

    g++: error: C:\Program: No such file or directory
    g++: error: Files\MySQL\MySQL: No such file or directory
    g++: error: Server: No such file or directory
    g++: error: 5.5\lib\libmysql.lib: No such file or directory
    mingw32-make[1]: *** [debug\MySQLTest02.exe] Error 1
    mingw32-make: *** [debug] Error 2

    I can't understand why
    "g++: error: C:\Program Files: No such file or directory"
    not "g++: error: C:\Program: No such file or directory"

    Is space not available on QtCreator ?



  • You just include

    @QT += sql@

    in the .pro file. You can specify the path of your database in the source file as

    @
    QSqlDatabase db = QSqlDatabase::addDatabase("MySQL");
    db.setDatabaseName("C:\Program Files\MySQL\MySQL Server 5.5\include\databasename.db");
    db.open();
    @



  • @holygirl, I think his goal is to add the "specific" MySQL libraries and not using th QSqlDatabase class.

    @Hiwasawa

    add quotes (")
    here is the "explanation":http://doc.qt.digia.com/qt/qmake-project-files.html#whitespace



  • Oops! My bad. Thank you for pointing it out Code_ReaQtor.



  • Thank you for your reply !!!
    and now I tryed the way by "Code_ReaQtor".

    I tryed this code.

    INCLUDEPATH += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\include)
    LIBS += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.lib)

    And the error of build resolved!

    But,,,
    Now There is an error on Console.
    ----Eror message----------------------------------------------------------
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC

    but, my directory is this

    C:\Qt\4.8.4\include\QtSql\QMYSQLDriver
    C:\Qt\4.8.4\include\QtSql\QMYSQLResult

    how to use QMYSQL driver ?



  • my project is only this

    MySQLTest02--MySQLTest02.pro
    |
    -source---main.cpp

    MySQLTest02.pro---------------------------

    QT += core
    QT += sql
    QT -= gui

    INCLUDEPATH += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\include)
    LIBS += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.lib)

    TARGET = MySQLTest02
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app
    SOURCES += main.cpp

    main.cpp------------------------------------

    #include <QCoreApplication>
    #include <QSqlDatabase>
    #include <QDebug>
    #include <QSqlError>
    #include<iostream>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
     db.setHostName("localhost");
     db.setDatabaseName("test");
     db.setUserName("root");
     db.setPassword("hiwahiwa0715");
     if(!db.open()){
    
     }
    return a.exec&#40;&#41;;
    

    }




  • I had the same problem a few weeks ago.
    I solved it compiling in Release mode and adding the plugin libraries to the solution folder.
    Hope it helps you.

    Regards.



  • bq. INCLUDEPATH += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\include)
    LIBS += $$quote(C:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.lib)

    Correct me if I am wrong... you wanted to use MySQL in the QSqlDatabase?

    Then the thing you added in the .pro file has nothing to do with it...

    bq. QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC

    What you need is the QMYSQL plugin/driver for Qt. You actually need to build/rebuild Qt yourself and passing "-qt-sql-mysql" to configure



  • Thank you.

    Correct me if I am wrong… you wanted to use MySQL in the QSqlDatabase?
    Yeah, I want to use MySQL in th QSqlDatabase.
    I knew the module from a book about Qt from O'REILLY.
    but the book don't written about how to configure the environment.

    Then the thing you added in the .pro file has nothing to do with it…
    ohh, really? so how to recognition the Qtcreator to the include path of MySQL?

    What you need is the QMYSQL plugin/driver for Qt. You actually need to build/rebuild Qt yourself and >passing “-qt-sql-mysql” to configure

    ohh, it will need very very long time.


Log in to reply
 

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