1
votes

I'm trying to connect to SQL Server database on ubuntu in Qt and need to install ODBC driver. I did what document had told me to do here. And installed unixOBDC from here into /usr/local/unixODBC then running these commands

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

Which resulted in syntax error in couple of the sources

This is what i get if i run my code at the moment

QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

What am i missing?

Edit:

    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

1
try with: sudo apt-get install unixodbc-dev unixodbc-bin unixodbceyllanesc
That screencap is very hard to work with... Much better if you can copy-and-paste the text into a <pre>…</pre> block here.TallTed
@TallTed edited..Amir Heshmati
Note that Ubuntu has pre-built packages for this, you can apt-get install libqt5sql5-odbc tdsodbcnos
@nos i have tried that but no success..Amir Heshmati

1 Answers

1
votes

The problem could be caused by using wrong version of qmake. Most probably its not same as you use in source code.