Qt application crashing when using ODBC driver (macOS)



  • 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 :
    alt text

    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.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What version of Qt are you using ? With which version of Xcode ?

    Also, what did you use to build the plugin ?



  • Hello ,

    I'm using Qt 5.7.0 with Xcode 8.0 (on macOS Sierra)
    By the way i used the same code on another mac running OS X Yosemite (with Xcode 7.0) and the same problem occurs.

    I used unixODBC to build the plugin , i followed this tutorial from qt website.

    Thank you in advance ^^


  • Lifetime Qt Champion

    After a quick check, I'd recommend trying with iODBC.

    There seems to be a bug with unixODBC and unicode that results in stack corruption. If you have to use unixODBC, I can show you a patch for the Qt odbc driver to workaround that bug.



  • Hello ,
    yes i would prefer a workaround for the bug
    because when i tried to rebuild with iODBC , i got :

    "PROJECT ERROR : cannot load qmodule.pri"

    Ty


  • Lifetime Qt Champion

    How are you trying to build the driver ?



  • EDIT : i have to resolve the qmodule.pri error , even if i will workaround the bug ,
    because i have to rebuild with unixODBC due to an reinstallation of QT


  • Lifetime Qt Champion

    Again, how are you trying to build the driver and what exact error are you having ?



  • Here's how i did :

    I launch a terminal , and i type
    cd ~/Qt/5.7/Src/qtbase/src/plugins/sqldrivers/odbc

    then i type
    qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc" //Here's where the problem appears

    then i run a simple "make"

    it worked to first time , but when i tried to build the iODBC driver , it gives me the error. i that's why i reinstalled the whole Qt (but doesn't resolved a thing)


  • Lifetime Qt Champion

    what do you get if you call which qmake ?

    To be sure to use the right one, you should use the full path to the binary.



  • Thank you so much ,
    it turns out that my terminal is using another qmake , it worked when i used the full path.

    so i builded the iODBC driver with this command line :
    /Users/br4in/Qt5.6.2/5.6/clang_64/bin/qmake "INCLUDEPATH+=/usr/local/iODBC/include" "LIBS+=-L/usr/local/iODBC/lib -liodbc"

    it gave no errors , but the app is still crashing when i use the ODBC driver.

    it seems like an issue with QODBC , can you give me the tutorial to workaround the bug ?


  • Lifetime Qt Champion

    Just apply the patch you can find here and rebuild the driver.



  • I applied the patch , rebuilded the driver and my code.
    but the issue isn't fixed yet :(



  • Hi, it might be something with Oracle's .dylib for ODBC, which .dylib/client do you use?

    Qt's libqsqlodbc.dylib works fine for me, but I use it for MS SQLServer together with FreeTDS (libtdsodbc.so). Also in my Qt 5.7 libqsqlodbc.dylib was included so I didn't had to build it myself.

    Edit: looked at the crash screen above, it indeed seems that the crash is where @SGaist 's patch should help. You could try to patch again, but this time just comment out the whole function, something like this:

    static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode = 0)
    {
        return "";
    }
    

    That function just returns an additional diagnostic error message, so it's not really needed :-)



  • Hey , I commented the whole function as you said , except the two above lines :
    QString result;
    return result; (because if i type return " " , i will get a constructor error)
    then i rebuilded the driver and started a new project with the same code.

    the problem wasn't resolved . Maybe my libqsqlodbc.dylib is executing a different qsql_odbc.cpp file ?


  • Lifetime Qt Champion

    Did you install the driver ?


  • Lifetime Qt Champion

    Can you check again with 5.8 ?



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

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

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

    Symptom 4: Qt built/configured before installing unixODBC.

    1. Download and install unixODBC (must be done before installing freeTDS)
      Go -- > (www.unixODBC.org) / (Drivers) / (unixODBC-2.3.4.tar.gz)
      unzip and untar the packages.
      (Make sure you have write permissions otherwise run below last command with sudo prefix)
    ./configure --prefix=/usr/local/unixODBC
    make
    sudo make istall
    
    1. Download and install freeTDS:
      Go --> (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 install
    

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

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

    Note: 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");
    mydb.open()
    

    (Luck && !alas) = true.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.