Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. SQLite with QT SDK 1.1
Forum Updated to NodeBB v4.3 + New Features

SQLite with QT SDK 1.1

Scheduled Pinned Locked Moved Installation and Deployment
10 Posts 5 Posters 6.3k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    khalidmushtaq65
    wrote on last edited by
    #1

    Hi.

    I hope all of you will be fine.

    I want to use sqlite with QT. I am in some confusion while using it. I have some questions.

    1- How to use sqlite bundled with QT?
    2- How to use sqlite if downloaded from sqlite website?
    3- Which files to bundle with the application if sqlite is used?

    Thanks.

    Regards,
    Khalid Mushtaq

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on last edited by
      #2

      I don't remember if sqlite plugin is build in the standard installation. Otherwise you can see this link "http://doc.trolltech.com/4.7/sql-driver.html#qsqlite":http://doc.trolltech.com/4.7/sql-driver.html#qsqlite for build it.

      If you are in windows remember to deploy the sqlite lib, specially sqlite3.dll QtSql4.dll and the folder sqldriver that include qsqlite4.dll (i suppose deploy release version).

      1 Reply Last reply
      0
      • K Offline
        K Offline
        khalidmushtaq65
        wrote on last edited by
        #3

        Thanks stuk.

        Actually I want to ask that I downloaded the sqlite dll from http://www.sqlite.org/ now how to use it? How I can create a database in that file and how to use that database in QT and where to place that file?

        Hope you will get the point what I am trying to ask.

        Regards,
        Khalid Mushtaq

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          There is no needance in dll from official sqlite site. Qt has own SQLite support. You can read more about it in Assistant in QtSql section.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            khalidmushtaq65
            wrote on last edited by
            #5

            Ok.

            Then please tell me what to use in setHostName, setDatabase, username, password, port etc while connecting the database?

            How can I create a database in that SQLite?

            Regards,
            Khalid Mushtaq

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Just fill databaseName with path to your sqlite database file and you will get a connection :)

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Hostname, username and password are not needed for sqlite.

                Database name is the path to your database file. If you do not provide an absolute path, it is relative to your current working directory (the directory where your application executable lives, if you did not change it).

                The following snippet creates a sql database in file "testdb.sqlite" in directory "/tmp", and creates a test table in it.

                @
                QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
                db.setDatabaseName("/tmp/testdb.sqlite");
                db.open();
                qDebug() << db << db.isOpen();
                QSqlQuery q = db.exec("CREATE TABLE blurb ( id int, name varchar )");
                qDebug() << q.lastError();
                db.close();
                @

                Be aware, that the exec fails on a second and subsequent run of the snippet, due to the fact that the table already exists then.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dangelog
                  wrote on last edited by
                  #8

                  SQLite has the very nice CREATE TABLE IF NOT EXISTS statement.

                  http://www.sqlite.org/lang_createtable.html

                  Software Engineer
                  KDAB (UK) Ltd., a KDAB Group company

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [quote author="peppe" date="1296907715"]SQLite has the very nice CREATE TABLE IF NOT EXISTS statement.

                    http://www.sqlite.org/lang_createtable.html[/quote]

                    Nice! Good to know that. Thank's Peppe!

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      khalidmushtaq65
                      wrote on last edited by
                      #10

                      Thanks. Now I got the point:-)

                      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