Important: Please read the Qt Code of Conduct -

Can't get UNICODE support with QODBC and IBM DB2

  • I'm building an application to view some data in the database of my company's ERP, which is a DB2 database. The ERP app uses ODBC for the connection, so I'm using QODBC, together with the IBM ODBC Driver. However I cannot get Unicode characters from the DB. I've tried using QTextCodec, but I only get different crazy symbols with different codecs. I've been looking to use the QDB2 driver, but I need to compile that, which is impossible apparently, the closest I get is the qmake config giving a bunch of errors from the DB2 headers and libs. I'm not very familiar with qmake or QODBC, so any help/suggestion is greatly appreciated. Here's my connectionString (I've added the last append line and the setConnectOptions() to try to fix the issue, but nothing changes with or without those):

    QString connecString = "Driver={"+db2Driver+"};";
        return 0;
         QMessageBox::critical( nullptr, "Erro!", "Erro ao estabelecer a conexão:\n" + db2.lastError().text(), QMessageBox::Ok);
         qDebug() << "DB2 ERROR: " << db2.lastError().text();
         return 1;

  • Lifetime Qt Champion

    I don't see what Qt can do here - when the odbc driver does not return that it supports unicode, Qt can't use it. See for the needed checks.

  • Hi
    had the same problem some time ago and could only resolve it by changing the sources of the qt sql-drivers.
    Didnt test it with the current versions of qt/db2/odbc, so at least you should tell us about the versions u are using.


  • Qt 5.14.2 and IBM DB2 11.5

  • just tried to start my yesterday installed db2 v11.5, nothing happend. no usefull errormessage, no help for that.
    never seen such a crappy product...

  • Exactly, I hate IBM software because of this kind of stuff, no helpful support, terrible website...

  • trying different ways to install db2 11.5, but nothing worked. so idid some tests on an older machine with db2 9.x using the qt db2driver and everything works fine. so maybe we can help you building the qt db2 driver, normally an easy task.
    all you need are the header and lib files in your sqllib dir and then it should work as described in the docs:

      cd %QTDIR%\qtbase\src\plugins\sqldrivers
      qmake -- "DB2_PREFIX=<DB2 home>/sqllib"
      nmake sub-db2

    if that dont work you should show some errormessages...

  • Thank you for your help, can you please send me the headers and libs for that version of DB2?

  • I finally managed to build the driver with IBM DB2 11.5 libs and headers, turns out I just needed to use the MSVC 2017 compiler.
    Full unicode support now.
    Had some problems with the compiler in the past, but works just fine now, compile times for my program are vastly better too.

Log in to reply