Qt application crashing when using ODBC driver (macOS)

柔情痞子 提交于 2019-12-20 07:12:51

问题


My Qt application is crashing when i use ODBC driver to connect to Oracle database. The issue is a stack overflow. My code is

#include "mainwindow.h"
#include <QApplication>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlError>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSqlDatabase db= QSqlDatabase::addDatabase("QODBC3");
    db.setUserName("SYS");
    db.setPassword("oracle");
     if (!db.open()) {
        qDebug() << db.lastError().text();
     } else {
        qDebug("success");
     }
     MainWindow w;
     w.show();
     db.close();
     return a.exec();
}

The error that appears : error

I'm sure that there's no problem with the code , because i've tried it on a windows machine. Also i did build the ODBC driver with qmake.

I'm new to Qt , i'm probably doing something wrong.

Thank you.


回答1:


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");



来源:https://stackoverflow.com/questions/40093807/qt-application-crashing-when-using-odbc-driver-macos

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