SQLITE with QT Application...
-
-
Hi
do not have to compile the SQLite driver.simple example:
in *.pro file add line
@
QT += sql
@
and
@
#include <QtSql/QtSql>
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("fileName.db3");
db.open();
// db.close(); // for close connection
@more, depending on the task.
-
Another question...
I'm trying to open my generated database with some tables on SQLITEMAN and the SQLITEMAN does not show any table on the file...
I have used sqlite on android apps and I could open the SQLITE FILES on SQLITEMAN withtout any problems....It's a problem, it could not be done... anyone with the same "problem"?
thanks -
Could be the version, I read something that says Sqliteman just open sqlite3 files...
I make this code, case study code?
@
#include "banco.h"
#include "QtSql/QtSql"
#include "QDebug"Banco::Banco(QObject *parent) :
QObject(parent)
{
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName( QDir::homePath() + QDir::separator() + "inoveDB.db3");
if (db.open()) {
QSqlQuery query(db);
if (query.exec("CREATE TABLE usuario ( INTEGER oid PRIMARY KEY);")) {
qDebug() << "criado tabela com sucesso.";
} else {
qDebug() << "erro ao criar tabela." << query.lastError();
}
} else {
qDebug() << "DB Nao aberto.";
}
db.close();
@- brazillian portuguese debug messages.
If I run this code twice, I got error saying that already exists the table "usuario".
-
Hi and welcome to devnet,
Please don't revive old thread with new questions, open your own.
As for your question, have a look at the "Sql Example in Qt's documentation":http://qt-project.org/doc/qt-4.8/examples-sql.html
-
Its working. Just SQL part you using will generate error second time becouse table already exists. You could replace with CREATE TABLE IF NOT EXISTS ....
[quote author="dcbasso" date="1341519956"]Could be the version, I read something that says Sqliteman just open sqlite3 files...
I make this code, case study code?
@
#include "banco.h"
#include "QtSql/QtSql"
#include "QDebug"Banco::Banco(QObject *parent) :
QObject(parent)
{
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName( QDir::homePath() + QDir::separator() + "inoveDB.db3");
if (db.open()) {
QSqlQuery query(db);
if (query.exec("CREATE TABLE usuario ( INTEGER oid PRIMARY KEY);")) {
qDebug() << "criado tabela com sucesso.";
} else {
qDebug() << "erro ao criar tabela." << query.lastError();
}
} else {
qDebug() << "DB Nao aberto.";
}
db.close();
@- brazillian portuguese debug messages.
If I run this code twice, I got error saying that already exists the table "usuario".[/quote]