[solved] QSqlDatabase QSQLITE pointer?
-
wrote on 30 Dec 2013, 12:43 last edited by
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"
-
wrote on 30 Dec 2013, 12:46 last edited by
As ever, short after posting, I found the solution:
@ QSqlDatabase *databaseP = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));
databaseP->setDatabaseName("datastore.db");@ -
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
-
wrote on 30 Dec 2013, 20:00 last edited by
[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?
-
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.
-
wrote on 30 Dec 2013, 20:08 last edited by
Thanks, I will look into this!
-
wrote on 30 Dec 2013, 22:48 last edited by
I didn't know about QStandardPaths & Q_IMPORT_PLUGIN - very very useful. It all works now! Thank you!
-
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 :)
-
wrote on 6 Jan 2014, 16:57 last edited by
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/9