Qt 4.8 and MySQL plugin error



  • Hello everyone,

    I am new to Qt, I installed the 1.2 SDK version not a long time ago. I am trying to establish a connection with MySQL but in vain. I have tried lots of tutorials, this is driving me crazy since few days !

    • I have Windows 7 Home Premium 64 bits.
    • I installed the Qt SDK from an offline installer that I downloaded from the Nokia website, entitled : Qt_SDK_Win_offline_v1_2_en.exe ( I am using MSVC 2010 and not MinGW ), and the directory is C:\QtSDK
    • I installed MySQL Community Edition 64 bits from a MSI Installer that I downloaded from the MySQL website, entitled : mysql-5.5.22-winx64.msi

    I read somewhere that the lib and include folders of the 64 bits version of MySQL cannot be used for the plugin so I installed mysql-5.5.22-win32.msi on a virtual machine and copied the lib and include folders to C:\MySQL.

    Afterwards, I successfully executed the following commands :

    @cd C:\QtSDK\QtSources\4.8.0\src\plugins\sqldrivers\mysql
    qmake 'INCLUDEPATH+=c:/MySQL/include" "LIBS+=-Lc:/MySQL/lib" mysql.pro
    nmake debug
    nmake release@

    I then copied the files qsqlmysql4.dll , qsqlmysql4.lib , qsqlmysqld4.dll and qsqlmysqld4.lib to C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\plugins\sqldrivers.

    In addition I copied libmysql.lib ( from the include folder of MySQL ) to the following folders:

    • C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\plugins\sqldrivers
    • C:\QtSDK\QtSources\4.8.0\src\plugins\sqldrivers\mysql\release
    • C:\QtSDK\QtSources\4.8.0\src\plugins\sqldrivers\mysql\debug
    • The debug folder of my app
    • The release folder of my app

    I even added the path of the file libmysql.lib ( which is C:\MySQL\lib ) to the PATH environment variable of windows.

    I also tried to clear the cache by deleting the following folders in the registry :

    • HKEY_CURRENT_USER\Software\Trolltech\OrganizationDefaults\Qt Plugin Cache 4.x.false
    • HKEY_CURRENT_USER\Software\Trolltech\OrganizationDefaults\Qt Plugin Cache 4.x.debug

    My application consists of one cpp file that contains the following code :

    @# include <QApplication>

    include <QDebug>

    include <Qtsql/QSqlDatabase>

    include <QStringList>

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

    QCoreApplication a(argc, argv);
    qDebug() << QSqlDatabase::drivers();
    return a.exec&#40;&#41;;
    

    }@

    I am getting the following errors :

    @BusinessLogic.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QStringList __cdecl QSqlDatabase::drivers(void)" (_imp?drivers@QSqlDatabase@@SA?AVQStringList@@XZ) referenced in function _main

    debug\ETE.exe:-1: error: LNK1120: 1 unresolved externals
    @

    I will really appreciate any help !!

    Thank you in advance !!

    Leeeeeeelo.



  • You need to add the QtSql module in your Qt project file (.pro):

    @ QT += sql@



  • Hello JonasAH !

    Thank you for your prompt reply, but I actually forgot to mention that I already added this model in the .pro file, in vain :/

    Any other suggestions ??


Log in to reply
 

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