Qt application crashing when using ODBC driver (macOS)

霸气de小男生 提交于 2019-12-02 10:46:20

Steps to activate/test QODBC on Mac OS ((Seirra) towards MSSQL or any other ODBC DB:

Symptom 1: Qt Run (Debug) application crashes (program unexpectedly finished/crashed). Symptom 2: Qt Creator with pre-built Qt packages (MaintenanceTool).

Symptom 3: freeTDS driver (libtdsodbc.so) is missing after installing freeTDS packages.

Symptom 4: Qt built/configured before or with missing unixODBC.

  1. Download and install unixODBC (must be done before installing freeTDS) (www.unixODBC.org) / (Drivers) / (unixODBC-2.3.4.tar.gz)

unzip and untar the packages.

./configure --prefix=/usr/local/unixODBC (be sure you can write OR sudo)

make sudo make istall

  1. Download and install freeTDS: (http://www.freetds.org/) / ( Quick Links) / (Latest Versions) / (Stable Release)

untar/unzip the package.

./configure --prefix=/usr/local/freeTDS --with-unixodbc=/usr/local/unixODBC/

make

sudo make istall

Note: --with-unixodbc will cause the driver (libtdsodbc.so) to be installed.

  1. Unfortunately, possibly the ODBC plugin on Qt should be rebuilt:

    • If you are using the prebuilt Qt libraries, you will need to download sources using MaintenanceTool ($QTDIR/MaintenanceTool.app)

    • Tell qmake where to find the unixODBC header files and shared libraries (here it is assumed that unixODBC is installed in /usr/local/unixODBC) and run make:

    cd $QTDIR/qtbase/src/plugins/sqldrivers/odbc

    my case: cd /usr/local/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc

    qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"

    make

if that goes correctly: you will get complied QODBC new libs:

cd ../plugins/sqldrivers/

copy the new packages for example to :

/usr/local/Qt/5.9.1/clang_64/plugins/sqldrivers/
  1. Configure /etc/local/unixODBC/etc/odbc.ini (you might need root permissions to mdify)

(No need to configure freeTDS):

  • (which port ? which version -> Run /usr/local/freeTDS/bin/tsql -LH 192.168.x.x
  • Create/Modify entry in /usr/local/unixODBC/etc/odbc.ini

    [MYDSN]

    Driver = /usr/local/freeTDS/lib/libtdsodbc.0.so

    Server = 192.168.x.x

    Port = 51271

    1. in Qt project:

    QSqlDatabase mydb = QSqlDatabase::addDatabase("QODBC");

    mydb.setDatabaseName("MYDSN")

    mydb.setUserName("name on Database");

    mydb.setPassword(" password on Database");

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!