QMYSQL driver available but not loaded

后端 未结 9 1119
Happy的楠姐
Happy的楠姐 2020-12-03 12:17

How do I load qmysql driver in Qt? I have the following code that produces these results:

(\"QSQLITE\", \"QMYSQL\", \"QMYSQL3\") 
QSqlDatabase:          


        
相关标签:
9条回答
  • 2020-12-03 13:13

    On Windows (see as directory structure):

    the_qt_app.exe
    libmysql.dll
    sqldrivers/qsqlmysql4.dll
    
    0 讨论(0)
  • 2020-12-03 13:16

    We should check our driver first

    $ cd /opt/Qt5.2.1/5.2.1/gcc_64/plugins/sqldrivers
    

    then we can find some files

    Use the command below to check library

    $ ldd libqsqlmysql.so
    

    if you find the problem libmysqlclient_r.so.16 => not found it may be the library-dependency problem.

    After I did a little research on the Internet, there is a way would be easy.

    $ cd /usr/lib/x86_64-linux-gnu
    

    if you find libmysqlclient_r.so.18,

    $ cp libmysqlclient_r.so.18 libmysqlclient_r.so.16
    
    0 讨论(0)
  • 2020-12-03 13:17

    You can use QPluginLoader to get some better error message.

    When I had the same problem with the MySQL driver the message was something like "The version was compiled with other options than this Qt version".

    It seemed like the Qt sources, that shipped with the Qt SDK at that time, were not compatible with its binaries.

    After downloading the Qt sources and compiling my own version of Qt and the MySQL driver, the problem was gone.

    EDIT: Some sample code.

    QPluginLoader loader;
    loader.setFileName("/Users/niklaswulf/QtSDK/Qt/4.8.4/plugins/sqldrivers/libqsqlite_debug.dylib");
    qDebug() << loader.load();
    qDebug() << loader.errorString();
    
    loader.setFileName("/Users/niklaswulf/QtSDK/Qt/5.0.1/5.0.1/clang_64/plugins/sqldrivers/libqsqlite_debug.dylib");
    qDebug() << loader.load();
    qDebug() << loader.errorString();
    

    When compiling against 5.0.1 this is the output:

    false 
    "The file '/Users/niklaswulf/QtSDK/Qt/4.8.4/plugins/sqldrivers/libqsqlite_debug.dylib' is not a valid Qt plugin." 
    true 
    "Unknown error"
    

    I also found the old message:

    The plugin '/path/to/some/libqsqlmysql.dylib' uses incompatible Qt library. Expected build key "macosx macx-cocoa g++-4 full-config", got "macosx macx-cocoa g++-4 no-pkg-config"
    
    0 讨论(0)
提交回复
热议问题