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. [solved] QSqlDatabase QSQLITE pointer?

[solved] QSqlDatabase QSQLITE pointer?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.8k 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.
  • S Offline
    S Offline
    syfy323
    wrote on 30 Dec 2013, 12:43 last edited by
    #1

    Hello,

    how do I get a pointer out of QSqlDatabase with type QSQLITE?

    Non-Ptr:
    @ QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
    database.setDatabaseName("datastore.db");@

    Calling addDatabase on the pointer does not really work:
    @ QSqlDatabase *databaseP = new QSqlDatabase;
    databaseP->addDatabase("QSQLITE");
    databaseP->setDatabaseName("datastore.db");@

    bq. "Driver not loaded Driver not loaded"

    1 Reply Last reply
    0
    • S Offline
      S Offline
      syfy323
      wrote on 30 Dec 2013, 12:46 last edited by
      #2

      As ever, short after posting, I found the solution:
      @ QSqlDatabase *databaseP = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));
      databaseP->setDatabaseName("datastore.db");@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 30 Dec 2013, 19:53 last edited by
        #3

        Hi,

        Why do you need that pointer ? It's not the standard use of QSqlDatabase. Once you create the connection (which will be the default), all further calls to e.g. QSqlQuery will use the default connection

        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
        • S Offline
          S Offline
          syfy323
          wrote on 30 Dec 2013, 20:00 last edited by
          #4

          [quote author="SGaist" date="1388433230"]Hi,

          Why do you need that pointer ? It's not the standard use of QSqlDatabase. Once you create the connection (which will be the default), all further calls to e.g. QSqlQuery will use the default connection[/quote]

          Hi. You are right, I just did not know that until I prepared my first SQL-statement.

          A bit OT but is there Qt SQLite support for iOS? On Mac I can open my database (db->open();) but on iOS I get:

          @QSqlDatabase: QSQLITE driver not loaded
          QSqlDatabase: available drivers: @
          (end)

          Do I need an Qt-Plugin like AVMedia needs?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 30 Dec 2013, 20:04 last edited by
            #5

            Qt for iOS is a static build so you need to tell Qt which plugin you will be using. Look for Q_IMPORT_PLUGIN and the related documents in Qt's documentation.

            Also, beware that you cannot create files everywhere on iOS you only have access to some predefined folder, use QStandardPaths to retrieve these.

            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
            • S Offline
              S Offline
              syfy323
              wrote on 30 Dec 2013, 20:08 last edited by
              #6

              Thanks, I will look into this!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                syfy323
                wrote on 30 Dec 2013, 22:48 last edited by
                #7

                I didn't know about QStandardPaths & Q_IMPORT_PLUGIN - very very useful. It all works now! Thank you!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 30 Dec 2013, 23:34 last edited by
                  #8

                  You're welcome !

                  Now that you have it working, don't forget to update the thread title prepending [solved] so other forum users may know a solution has been found :)

                  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
                  • J Offline
                    J Offline
                    jraichouni
                    wrote on 6 Jan 2014, 16:57 last edited by
                    #9

                    Hi syfy323!

                    Would you be so kind and have a quick look at my post at the bottom under "Qt 5.1 ios How to Bundle and use SQLite database in application":http://qt-project.org/forums/viewthread/34102 ?

                    I have the same problem but do not get it to work.

                    Would be great!

                    Thanks and cheers
                    jraichouni

                    1 Reply Last reply
                    0

                    1/9

                    30 Dec 2013, 12:43

                    • Login

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