SOLVED Qt 5.1 ios How to Bundle and use SQLite database in application
-
wrote on 5 Jan 2014, 00:32 last edited by
Alright, missed that and now the same error appears as I got it in my original project yesterday.
Xcode says:
@
Undefined symbols for architecture i386:
"qt_static_plugin_qsqlite()", referenced from:
StaticqsqlitePluginInstance::StaticqsqlitePluginInstance() in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@
Does anything from my Qt (iOS) Installation (e.g. from plugin sqldrivers) need to be copied/ deployed into the build for iOS Simulator?Or do I need to specify the -spec argument within the call of qmake because of that architecture error above?
-
wrote on 6 Jan 2014, 17:02 last edited by
@ QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
QString dbFile = paths.first().append("/datastore.db");QSqlDatabase *database = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE")); database->setDatabaseName( dbFile );@
Add this to your .pro:
QT += sql
QTPLUGIN += qsqliteAs explained here (inclusing your cross post):
http://qt-project.org/forums/viewthread/36600/#156960
... (by SGaist) using a pointer is not necessary. -
wrote on 6 Jan 2014, 17:32 last edited by
Tried it, and Xcode fails with below error. Did you try to build it for iOS Simulator?
@
Undefined symbols for architecture i386:
"qt_static_plugin_qsqlite()", referenced from:
StaticqsqlitePluginInstance::StaticqsqlitePluginInstance() in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@
Used as you proposed:
@sqlite_on_ios.pro
TEMPLATE = app
QT += qml quick sql
QTPLUGIN += qsqlite
QMAKE_INFO_PLIST += Info.plist
SOURCES += main.cpp
RESOURCES += main.qrc
cache()
@My main.cpp:
@
// main.cpp
#include <QGuiApplication>
#include <QQuickView>
#include <QString>
#include <QtPlugin>Q_IMPORT_PLUGIN(qsqlite)
#include <QSqlDatabase>int main(int argc, char *argv[]) {
QGuiApplication *app = new QGuiApplication(argc, argv);
// QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "xa_db");
QQuickView *view = new QQuickView;
view->setSource(QUrl("qrc:///main.qml"));
view->setResizeMode(QQuickView::SizeRootObjectToView);
view->show();
return app->exec();
}
@ -
wrote on 6 Jan 2014, 17:35 last edited by
I am using a recent version of Qt 5.2.0-dev snapshot (in the title you are writing you are using 5.1).
For iOS development you should stick to 5.2.0 instead of < 5.2.0.edit: yes, I did - works for Mac, iOS Sim and on my iPhone.
-
wrote on 6 Jan 2014, 18:24 last edited by
I am using "Qt 5.2.0 (official release)":http://download.qt-project.org/official_releases/qt/5.2/5.2.0/qt-mac-opensource-5.2.0-ios-x86_64-offline.dmg
I did not create the thread.
A very short but complete mini project .pro file & main.cpp would help.
I mean an example, which runs at your computer. I would launch qmake only to get the .xcodeproject directory to test that.
-
wrote on 6 Jan 2014, 18:27 last edited by
[quote author="jraichouni" date="1389032658"]I am using "Qt 5.2.0 (official release)":http://download.qt-project.org/official_releases/qt/5.2/5.2.0/qt-mac-opensource-5.2.0-ios-x86_64-offline.dmg
I did not create the thread.[/quote]
Oh, sorry.
drop this from your file:
Q_IMPORT_PLUGIN(qsqlite)edit for your edit:
[quote author="jraichouni" date="1389032658"]
A very short but complete mini project .pro file & main.cpp would help.I mean an example, which runs at your computer. I would launch qmake only to get the .xcodeproject directory to test that.[/quote]
I already did - the code above works as your main() content.
-
wrote on 6 Jan 2014, 18:31 last edited by
It runs!
I am a bit confused, as the "Plug & paint example":http://qt-project.org/doc/qt-4.8/tools-plugandpaint.html uses that macro.But many thanks for your reply and help!!
Really interesting would be to be able to use the SQLite Function "load_extension" which is omitted in Standard Qt build.
-
wrote on 6 Jan 2014, 18:34 last edited by
[quote author="jraichouni" date="1389033119"]It runs!
I am a bit confused, as the "Plug & paint example":http://qt-project.org/doc/qt-4.8/tools-plugandpaint.html uses that macro.But many thanks for your reply and help!![/quote]
You're welcome.
-
wrote on 8 Jan 2014, 13:46 last edited by
"A very short but complete mini project .pro file & main.cpp would help.
I mean an example, which runs at your computer. I would launch qmake only to get the .xcodeproject directory to test that."I just start to use QT 5.2 (with iOS even more) a mini exemple project with all files would be great
-
wrote on 8 Jan 2014, 18:38 last edited by
Hi!
Take the example in the current thread.
The important things to consider are:
.pro file:
@
QT += sql
ios:QTPLUGIN += qsqlitedeploy the database file via something like:
databases.files = ../../src/data/xp-apt.sqlite
ios: databases.path = Documents
macx: databases.path = Contents/Resources
QMAKE_BUNDLE_DATA += databasesnote, that the path databases.files is relative to the cwd, in which
the process qmake runs
@
The class implementing the initialisation/ access to the db needs to do the following for instance:
@
#include <QtSql>
(...)QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "some_name");
QSqlDatabase db = QSqlDatabase::database("some_name", false);
QString dbFilePath = "(...)";
db.setDatabaseName(dbFilePath);
db.open();
QSqlQuery *q = new QSqlQuery(db);
(...)
@Hope that helps!
-
wrote on 28 Jan 2014, 14:52 last edited by
Hi!
I'm follow this example.
But It doesn't work for me.In Desktop, iOS simulator mode is fine.
But it doesn't work with my iPad.Thanks you if you can help me.
-
wrote on 29 Jan 2014, 14:12 last edited by
I currently work on my work environment and do also have no iPad (iPhone only) but it shall work as described in above posts.
-
wrote on 30 Jan 2014, 04:03 last edited by
Hi, Jamil
Thanks for your feedback.
Then I tried with my iPhone5s. And It just work, but my iPadRetina don't.
Post QT creator error log above:This plugin does not support propagateSizeHints()
&
Failed to make complete framebuffer object 8cddThanks again for your help.
-
wrote on 21 Feb 2014, 06:42 last edited by
[Solved]
Update to QT5.2.1, iPad just work fine.Thanks you.
-
wrote on 21 Jun 2014, 04:38 last edited by
Hi,
Please help. I build my app for iPad, and using database Sqlite.
Can you explain the QString dbFilePath = "(...)"; why it is "(...)"
Thanks and regards[quote author="Jamil Raichouni" date="1389206294"]Hi!
Take the example in the current thread.
The important things to consider are:
.pro file:
@
QT += sql
ios:QTPLUGIN += qsqlitedeploy the database file via something like:
databases.files = ../../src/data/xp-apt.sqlite
ios: databases.path = Documents
macx: databases.path = Contents/Resources
QMAKE_BUNDLE_DATA += databasesnote, that the path databases.files is relative to the cwd, in which
the process qmake runs
@
The class implementing the initialisation/ access to the db needs to do the following for instance:
@
#include <QtSql>
(...)QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "some_name");
QSqlDatabase db = QSqlDatabase::database("some_name", false);
QString dbFilePath = "(...)";
db.setDatabaseName(dbFilePath);
db.open();
QSqlQuery *q = new QSqlQuery(db);
(...)
@Hope that helps![/quote]
-
It's a placeholder text that you must replace with the path to your database file
-
wrote on 26 Jun 2014, 04:28 last edited by
Thanks SGaist,
It works now. -
wrote on 31 Aug 2017, 08:26 last edited by
hi every body,
i ve the same issue, should this mean that we don't need to use Q_IMPORT_PLUGIN(qsqlite);
any more for static compiling?