Compiling MySQL Plugin for Qt 4.8.1 on Windows with Visual Studio 2010 C++ -
the qt project not provide mysql database drivers qt sql module 1 have use odbc or compile plugin manually. trying latter. have been using pre-built qt 4.8.1 vs 2010 , fail find plugin's project file (mysql.pro) in "c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/" numerous tutorials use. there qsql_mysql.pri following contents:
headers += $$pwd/qsql_mysql.h sources += $$pwd/qsql_mysql.cpp # modified! added these: #includepath += "c:/program files (x86)/mysql/mysql server 5.6/include" #libs += "c:/program files (x86)/mysql/mysql server 5.6/lib/libmysql.lib" unix { isempty(qt_lflags_mysql) { !contains(libs, .*mysqlclient.*):!contains(libs, .*mysqld.*) { use_libmysqlclient_r:libs += -lmysqlclient_r else:libs += -lmysqlclient } } else { libs *= $$qt_lflags_mysql qmake_cxxflags *= $$qt_cflags_mysql } } else { !contains(libs, .*mysql.*):!contains(libs, .*mysqld.*):libs += -llibmysql }
building results in following errors:
release\moc_qsql_mysql.cpp(45) : warning c4273: 'qmysqldriver::qt_static_metacall': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'qt_static_metacall' release\moc_qsql_mysql.cpp(57) : warning c4273: 'staticmetaobjectextradata': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'private: static qmetaobjectextradata const qmysqldriver::staticmetaobjectextradata' release\moc_qsql_mysql.cpp(57) : error c2491: 'qmysqldriver::staticmetaobjectextradata': definition of static member dllimport not valid release\moc_qsql_mysql.cpp(61) : warning c4273: 'staticmetaobject': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'public: static qmetaobject const qmysqldriver::staticmetaobject' release\moc_qsql_mysql.cpp(61) : error c2491: 'qmysqldriver::staticmetaobject': definition of static member dllimport not valid release\moc_qsql_mysql.cpp(71) : warning c4273: 'qmysqldriver::metaobject': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'metaobject' release\moc_qsql_mysql.cpp(76) : warning c4273: 'qmysqldriver::qt_metacast': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'qt_metacast' release\moc_qsql_mysql.cpp(84) : warning c4273: 'qmysqldriver::qt_metacall': inconsistent dll-binding. c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h(104): see previous definition of 'qt_metacall' c:\qtsdk\qtsources\4.8.1\src\sql\drivers\mysql\qsql_mysql.cpp(47) : fatal error c1083: file (include) not opened: "qsqlerror.h": no such file or directory
this happens when try manually crafted mysql.pro pretty identical:
libs += "c:/program files (x86)/mysql/mysql server 5.6/lib/libmysql.lib" includepath += "c:/program files (x86)/mysql/mysql server 5.6/include/" sources += "c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.cpp" headers += "c:/qtsdk/qtsources/4.8.1/src/sql/drivers/mysql/qsql_mysql.h"
this might version closer original.
another question regarding licensing of approach: building plugin using qt sources require publishing sources used , / or there limitations using module dynamic library (no static linking allowed commercial purposes qt open source).
i got wrong path! file mysql.pro exists in c:\qtsdk\qtsources\4.8.1\src\plugins\sqldrivers\mysql
target = qsqlmysql # added these 2 lines after copying # c:\program files (x86)\mysql\mysql server 5.6 libs += lib/libmysql.lib includepath += include/ sources = main.cpp include(../../../sql/drivers/mysql/qsql_mysql.pri) include(../qsqldriverbase.pri)
now build plugin. copied files c:\qtsdk\desktop\qt\4.8.1\msvc2010\plugins\sqldrivers
run mysql admin
"c:\program files (x86)\mysql\mysql server 5.6\bin\mysqld.exe" --defaults-file="c:\programdata\mysql\mysql server 5.6\my.ini"
but though copied dlls qt's plugin directory
c:\qtsdk\desktop\qt\4.8.1\msvc2010\plugins\sqldrivers
they not found:
qsqldatabase: qmysql driver not loaded qsqldatabase: available drivers: qsqlite qodbc3 qodbc qsqlerror(-1, "driver not loaded", "driver not loaded")
this answer qt 4.8.0 - mysql driver not listed has solution:
to use make sure have path find libmysql.dll (usually c:\mysql\bin) part of environment variable path.
or copy dll qt project dir root..
Comments
Post a Comment