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. SQLITE with QT Application...
QtWS25 Last Chance

SQLITE with QT Application...

Scheduled Pinned Locked Moved General and Desktop
13 Posts 7 Posters 50.2k Views
  • 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 Offline
    D Offline
    dcbasso
    wrote on 5 Jul 2012, 14:00 last edited by
    #1
    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
    0
    • D Offline
      D Offline
      dmcr
      wrote on 5 Jul 2012, 14:18 last edited by
      #2

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

      dmcr

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Skyrim
        wrote on 5 Jul 2012, 16:16 last edited by
        #3

        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
        0
        • D Offline
          D Offline
          dcbasso
          wrote on 5 Jul 2012, 16:35 last edited by
          #4

          Thanks!

          Skyrim, where you find this example?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on 5 Jul 2012, 19:45 last edited by
            #5

            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
            0
            • F Offline
              F Offline
              franku
              wrote on 5 Jul 2012, 20:22 last edited by
              #6
              • 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
              0
              • D Offline
                D Offline
                dcbasso
                wrote on 5 Jul 2012, 20:25 last edited by
                #7

                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
                0
                • F Offline
                  F Offline
                  franku
                  wrote on 5 Jul 2012, 20:41 last edited by
                  #8

                  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
                  0
                  • D Offline
                    D Offline
                    dcbasso
                    wrote on 5 Jul 2012, 21:16 last edited by
                    #9

                    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
                    0
                    • D Offline
                      D Offline
                      dcbasso
                      wrote on 5 Jul 2012, 21:18 last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pemoamsi
                        wrote on 27 Aug 2013, 10:45 last edited by
                        #11

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

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 27 Aug 2013, 11:12 last edited by
                          #12

                          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
                          0
                          • D Offline
                            D Offline
                            drsasa
                            wrote on 15 Dec 2013, 21:30 last edited by
                            #13

                            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
                            0

                            • Login

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