Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Cant get data from SQLite



  • Hey,

    I am trying to read data out of a sqlite3 table. I've already tried a lot to get this work but nothing worked. I am new to programing so please excuse my mistakes :)

    Here is my Project file:

    @#-------------------------------------------------

    Project created by QtCreator 2014-04-22T23:50:07

    #-------------------------------------------------

    QT += core
    QT += sql

    QT -= gui

    TARGET = SQL_TEST
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    @

    main.cpp

    @#include <QCoreApplication>
    #include <QDebug>
    #include <QtSql>
    #include <QSqlDatabase>
    #include <QSqlQuery>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/home/adx/Schreibtisch/sqlite.db");
    
    
    if(db.open())
    {
        qDebug() << "db.open returns true";
    
        qDebug() << "Avalible QSqlDatabase Drivers = " << QSqlDatabase::drivers();
        qDebug() << "tables:" << db.tables();
        QSqlQuery query(db);
        query.exec&#40;"select * from acc2"&#41;;
        qDebug(&#41; << "query.first = " << query.first();
        qDebug() << "query.isActive = " << query.isActive();
    
    
        qDebug() << "query.value:" << query.value(0).toString();
        qDebug() << db.lastError().text();
    

    }

       db.close();
    
    
    
    return a.exec&#40;&#41;;
    

    }@

    my console output:

    !http://www7.pic-upload.de/27.04.14/2chord89p4.png(console output)!

    my sqlite3 table:

    !http://www7.pic-upload.de/27.04.14/pof3wk54kr2q.png(sqlite3 table)!

    I am very thankful for your help!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From your Qt software you are giving this

    @"/home/adx/Schreibtisch/sqlite.db"@

    path to load your database.

    From your console you are giving:

    @"/home/adx/Schreibtisch/DATENDBANKEN/sqlite.db"@

    They don't match



  • Oh my god it works :D Ive tried everything to get it work and didnt check the path.. im such an idiot.

    thank you very much for your help!


  • Lifetime Qt Champion

    You're welcome !

    Since you have your database up and running, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply