Difference between revisions of "Development/Tutorials/SqLite"

Jump to: navigation, search
Line 1: Line 1:
 +
<pre>
 +
#include <QtSql>
 +
 +
int main(int argc, char *argv[])
 +
{
 +
    QSqlDatabase db;
 +
    db=QSqlDatabase::addDatabase("QSQLITE");
 +
    db.setDatabaseName("sqlite.dat");
 +
 +
    if (db.open())
 +
        qDebug() << "success";
 +
    else
 +
        qDebug() << "failed";
 +
    QSqlQuery query;
 +
    query.exec("create table stocks(id int primary key, name varchar(20))");
 +
    db.commit();
 +
    db.close();
 +
}
 +
</pre>
 +
 
<pre>
 
<pre>
 
QT      += core gui sql
 
QT      += core gui sql
Line 16: Line 36:
 
= See also =
 
= See also =
 
http://doc.trolltech.com/4.5/sql-relationaltablemodel.html
 
http://doc.trolltech.com/4.5/sql-relationaltablemodel.html
 +
http://commits.kde.org/kdeexamples/23d2202b0e7aca8999928374746da5733712ebc8

Revision as of 10:46, 10 November 2011

#include <QtSql>

int main(int argc, char *argv[])
{
    QSqlDatabase db;
    db=QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("sqlite.dat");

    if (db.open()) 
        qDebug() << "success";
    else 
        qDebug() << "failed";
    QSqlQuery query;
    query.exec("create table stocks(id int primary key, name varchar(20))");
    db.commit();
    db.close();
}
QT       += core gui sql

TARGET = sqlite
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

See also

http://doc.trolltech.com/4.5/sql-relationaltablemodel.html http://commits.kde.org/kdeexamples/23d2202b0e7aca8999928374746da5733712ebc8


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal