QMYSQL driver available but not loaded

后端 未结 9 1143
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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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"
    

提交回复
热议问题