Connecting to ODBC (Pervasive SQL) database

  • Hello,

    I need a way to work with Pervasive Database. I've been searching and testing for hours, trying to find a way to do it.. I'm not a complite stranger to C++ and Qt, but I would count myself a beginner and I'm struggling very much with this. I have managed to build the ODBC driver (atleast I think I did), as my C:\Qt\Qt5.0.1\5.0.1\Src\qtbase\plugins\sqldrivers -folder now has four files:


    So, the problem is, that whenever I search the internet for solutions, most of the answers are based on earlier versions of Qt. I'm not with Qt5.0.1, and for example, all of the examples I have found, just include #include <QtSql>. If I start with that, I just get:

    "QtSql: No such file or directory".

    So, with a little improvising, this is my very basic ODBC test code so far:

    #include <QCoreApplication>
    #include <QtSql/QODBCDriver>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);
    QString servername = "LOCALHOST" ;
    QString dbname = "DEMODATA";
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    QString dsn = QString("DRIVER={Pervasive ODBC Engine Interface);SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);

    return a.exec();

    These things I'm not sure about:

    1. Is that include right?
    2. If the database files are in my local computer, is it right to use LOCALHOST as Servername?
    3. I've gotten that driver name from ODBC Management. I can access the database from Pervasive Control Center just fine, and that driver name is presented in the settings of the database (in Pervasive Control Center).

    Anyway, with this code I get the following errors:

    F:\Arkisto\Qt\test_bench\main.cpp:35: error: variable 'QSqlDatabase db' has initializer but incomplete type
    F:\Arkisto\Qt\test_bench\main.cpp:35: error: incomplete type 'QSqlDatabase' used in nested name specifier

    Thank you in advance, I really hope I find a solution to get this thing started, I'm usually good at learning things from examples and stuff, when I get the basic code working.. But this one really seems hard for me :P

  • Library Qt consists of several modules.
    You need to add the following code to your .pro ​​file:

    QT += sql

    You also need to include the header in your main file:

    //#include <QtSql/QODBCDriver> - no needed
    #include <QSqlDatabase>

  • Okay, thanks, that got me forward!

    I now compiled and ran the program. At first, I got errors:

    QSqlDtabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE

    After that, I copied the files I from C:\Qt\Qt5.0.1\5.0.1\Src\qtbase\plugins\sqldrivers to C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\sqldrivers (is this right?) and now the program runs without errors!

    What would be the next step? If you can provide me with a good tutorial, that would be even better, I can just ask here again if I have too much trouble ;)

    EDIT: I've managed to connect to the demodata -database now, and made some basic queries based on this example:

    I'll keep trying stuff. Thank you so much Konstantin Podsvirov for your help so far, I'll post more questions if I face problems that I cannot solve myself..

  • Typically, the driver ODBC comes pre-assembled for windows.
    In the version of "Qt 5.0.2 for Windows 32-bit": is it just there (I checked).
    Separate assembly and manually copying is also possible, if necessary.
    Books can be found "here":
    At the time I was reading "Max Schlee":

Log in to reply

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