Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    SQLITE with QT Application...

    General and Desktop
    7
    13
    49621
    Loading More Posts
    • 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.
    • D
      dcbasso last edited by

      1. How to add SQLITE suporte to my application?
      2. I will need to compile the SQLITE driver?
      3. Have any step-by-step example?

      Thanks everyone.

      1 Reply Last reply Reply Quote 0
      • D
        dmcr last edited by

        http://doc.qt.nokia.com/4.7-snapshot/sql-driver.html#qmysql

        dmcr

        1 Reply Last reply Reply Quote 0
        • S
          Skyrim last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • D
            dcbasso last edited by

            Thanks!

            Skyrim, where you find this example?

            1 Reply Last reply Reply Quote 0
            • D
              dcbasso last edited by

              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

              1 Reply Last reply Reply Quote 0
              • F
                franku last edited by

                • different sqlite versions?
                • did you at least generate any table in the database (qsqlquery, qsqltablemodel, ...)?

                ;-) .. frank

                This, Jen, is the internet.

                1 Reply Last reply Reply Quote 0
                • D
                  dcbasso last edited by

                  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".

                  1 Reply Last reply Reply Quote 0
                  • F
                    franku last edited by

                    Hmm, code looks quite good. Have you tried the Firefox Plugin "SQLite Manager"? Sqlite3 is Qt-default as far as I know.

                    This, Jen, is the internet.

                    1 Reply Last reply Reply Quote 0
                    • D
                      dcbasso last edited by

                      I read the documentation, and the Qt uses Sqlite2 only if you include the sqlite2, by default really appers to be sqlite3.
                      I will try try Sqlite Manager.

                      1 Reply Last reply Reply Quote 0
                      • D
                        dcbasso last edited by

                        With Firefox Plugin show my "usuario" table! So my code works!
                        Another detail: Sqliteman uses QT!

                        1 Reply Last reply Reply Quote 0
                        • P
                          pemoamsi last edited by

                          Can someone give me and example or complete code of an app with sqlite please?

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            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

                            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 Reply Quote 0
                            • D
                              drsasa last edited by

                              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]

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post