QSqlDatabase sqlite and tracing

  • Hallo all,

    I am developing an QT application that stores data in a Sqlite database. For data retreaval and manipulation I am using the QSqlRelationalTableModel and the QSqlDatabase with "QSQLITE" driver.

    I would like to know if there is any way to implement tracing in qt, since sqlite doesn't have any profiler. So I would like to know what queryies are sent to the database.

    Thank you for your answer

  • Hi andruj, you may finde a perfect solution for this in:

  • I woud suggest not using the QSqlRelationalTableModel. In the past I have created a Database class which has all the methods for interacting with the database using QSqlQuery. I think it much more rohbust to do it this way. Granted there is more code to write, But it allows you to know programatically what's going on with the database. Below is a tiny example of what I mean.

    class Database
    typedef enum { People, Pets, Food, NumOfTables} TableType;
    // database methods
    bool open(QString &name);
    bool close();
    bool createTable(TableType);
    bool validateTable(TableType);
    QString getLastError();

    // People Methods
    People *getPeople();
    bool addPerson(Person *);
    bool removePerson(int PersonID);
    static QString tableNames[NumOfTables];
    static QString schemas[NumOfTables];
    QSqlDatabase *handle;
    QString errorMessage;
    QString name;
    QString description;
    QSqlError sqlError;

  • thank you for the replays.

    I will try the solution of stackoverflow.

    @DBoosalis: I will try to stick with the qsqlrelationaltablemodel, since the application isn't too complex. If I will have a more complex app I will certanly use your solution.

    thank you

Log in to reply