Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Cant get data from SQLite
Forum Updated to NodeBB v4.3 + New Features

[Solved] Cant get data from SQLite

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adx1
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adx1
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved