[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 += sqlQT -= gui
TARGET = SQL_TEST
CONFIG += console
CONFIG -= app_bundleTEMPLATE = 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("select * from acc2"); qDebug() << "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();
}@
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!
-
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
-
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 :)