我正在尝试连接到Qt中的ubuntu上的SQL Server数据库,需要安装ODBC驱动程序。
我做了文件告诉我要做的here。并将here中的unixOBDC安装到/usr/local/unixODBC
,然后运行这些命令
cd ~/Qt5.7.0/5.7/Src/qtbase/src/plugins/sqldrivers/odbc
qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
make
出现语法错误
如果我现在运行我的代码,这就是我得到的
QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
我缺少什么?
编辑:
makeg++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -fno-exceptions -Wall -W -Wvla -Wdate-time -D_REENTRANT -fPIC -DQT_NO_TSLIB -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.5.1 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.5.1/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -I../../../../mkspecs/linux-g++-64 -o .obj/qsql_odbc.o ../../../sql/drivers/odbc/qsql_odbc.cpp ../../../sql/drivers/odbc/qsql_odbc.cpp:193:44: error: ISO C++ forbids declaration of ‘Q_DECLARE_SQLDRIVER_PRIVATE’ with no type [-fpermissive] Q_DECLARE_SQLDRIVER_PRIVATE(QODBCDriver) ^ ../../../sql/drivers/odbc/qsql_odbc.cpp:193:44: error: expected ‘;’ at end of member declaration ../../../sql/drivers/odbc/qsql_odbc.cpp: In constructor ‘QODBCResultPrivate::QODBCResultPrivate(QODBCResult*, const QODBCDriver*)’: ../../../sql/drivers/odbc/qsql_odbc.cpp:198:33: error: no matching function for call to ‘QSqlResultPrivate::QSqlResultPrivate(QODBCResult*&, const QODBCDriver*&)’ hasSQLFetchScroll(true) ^ In file included from ../../../sql/drivers/odbc/qsql_odbc.cpp:59:0: /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql/private/qsqlresult_p.h:67:5: note: candidate: QSqlResultPrivate::QSqlResultPrivate() QSqlResultPrivate() ^ /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql/private/qsqlresult_p.h:67:5: note: candidate expects 0 arguments, 2 provided /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql/private/qsqlresult_p.h:63:20: note: candidate: QSqlResultPrivate::QSqlResultPrivate(const QSqlResultPrivate&) class Q_SQL_EXPORT QSqlResultPrivate ^ /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql/private/qsqlresult_p.h:63:20: note: candidate expects 1 argument, 2 provided ../../../sql/drivers/odbc/qsql_odbc.cpp:200:30: error: ‘drv_d_func’ was not declared in this scope unicode = drv_d_func()->unicode; ^ ../../../sql/drivers/odbc/qsql_odbc.cpp: In member function ‘void* QODBCResultPrivate::dpEnv() const’: ../../../sql/drivers/odbc/qsql_odbc.cpp:209:49: error: ‘drv_d_func’ was not declared in this scope SQLHANDLE dpEnv() const { return drv_d_func() ? drv_d_func()->hEnv : 0;} ^ ../../../sql/drivers/odbc/qsql_odbc.cpp: In member function ‘void* QODBCResultPrivate::dpDbc() const’: ../../../sql/drivers/odbc/qsql_odbc.cpp:210:49: error: ‘drv_d_func’ was not declared in this scope SQLHANDLE dpDbc() const { return drv_d_func() ? drv_d_func()->hDbc : 0;} ^ ../../../sql/drivers/odbc/qsql_odbc.cpp: In member function ‘bool QODBCResultPrivate::isStmtHandleValid()’: ../../../sql/drivers/odbc/qsql_odbc.cpp:228:42: error: ‘drv_d_func’ was not declared in this scope return disconnectCount == drv_d_func()->disconnectCount; ^ ../../../sql/drivers/odbc/qsql_odbc.cpp: In member function ‘void QODBCResultPrivate::updateStmtHandleState()’: ../../../sql/drivers/odbc/qsql_odbc.cpp:233:34: error: ‘drv_d_func’ was not declared in this scope disconnectCount = drv_d_func()->disconnectCount; ^ ../../../sql/drivers/odbc/qsql_odbc.cpp: In constructor ‘QODBCResult::QODBCResult(const QODBCDriver*)’: ../../../sql/drivers/odbc/qsql_odbc.cpp:959:51: error: no matching function for call to ‘QSqlResult::QSqlResult(QODBCResultPrivate&)’ : QSqlResult(*new QODBCResultPrivate(this, db)) ^ In file included from /usr/include/x86_64-linux-gnu/qt5/QtSql/5.5.1/QtSql/private/qsqlresult_p.h:51:0, from ../../../sql/drivers/odbc/qsql_odbc.cpp:59: /usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlresult.h:69:5: note: candidate: QSqlResult::QSqlResult(QSqlResultPrivate&, const QSqlDriver*) QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db); ^ /usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlresult.h:69:5: note: candidate expects 2 arguments, 1 provided /usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlresult.h:68:14: note: candidate: QSqlResult::QSqlResult(const QSqlDriver*) explicit QSqlResult(const QSqlDriver * db); ^ /usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlresult.h:68:14: note: no known conversion for argument 1 from ‘QODBCResultPrivate’ to ‘const QSqlDriver*’ ../../../sql/drivers/odbc/qsql_odbc.cpp: In member function ‘virtual bool QODBCResult::exec()’: ../../../sql/drivers/odbc/qsql_odbc.cpp:1464:36: error: ‘class QODBCResultPrivate’ has no member named ‘drv_d_func’ int precision = d->drv_d_func()->datetime_precision - 20; // (2 ^ ../../../sql/drivers/odbc/qsql_odbc.cpp:1480:42: error: ‘class QODBCResultPrivate’ has no member named ‘drv_d_func’ d->drv_d_func()->datetime_precision, ^ Makefile:463: recipe for target '.obj/qsql_odbc.o' failed make: *** [.obj/qsql_odbc.o] Error 1
答案 0 :(得分:1)
使用错误版本的qmake可能会导致问题。最可能与您在源代码中使用的不一样。