SQLITE Database in Project
Page |
1 |
Hello everybody,
i am trying to load data from an sqlite database.
with the simulator it is possible to open the db when i use the following, but then the db is stored on “C:” and not in my projects folder. so i think that it would not work on device without copying the db manually.
- db.setDatabaseName("/db.sqlite");
because of that i tried to add it to my ressources like a picture:
- db.setDatabaseName(":/database/db.sqlite");
(of course added in the .qrc file)
but with this code its not working on device as well as with the simulator, because “open” fails.
I think the App can’t find the db, but why?
Thanks you in advance!
18 replies
SQLite databases cannot be stored in the Qt resource system. You must put it into regular files and distribute them along your application.
The reason is simple: The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.
ok, thanks for info!
but now i have a problem!
how can i use the information in the file/db in my app?
i’d like to read and write to that file/db and want to bring the file/db with the app, so that i don’t need to copy it on device manually.
or is there another way to add it to my project? without the .qrc?
Hi All,
I have tried in the same way.But i didnt get it.
Basically i am developing the meego application in windows dev enviornment using Qt creator.
Following are my pro file contents,
- QT += core gui sql
- TARGET = AppName
- TEMPLATE = app
- target.path=/usr/local/bin
- INSTALLS=target
- SOURCES += ---\
- ---
- HEADERS += ---\
- ---\
- FORMS += ---\
- ---
- RESOURCES += \
- assests.qrc
- addFiles.sources =test.sqlite
- addFiles.path = .
- DEPLOYMENT += addFiles
So when i tried to build the file, automatically the other folde is added into my project directory and showing test.sqlite inside it;
But when i tried with the following code
- db.setDatabaseName(dbname);
- if(db.open())
- {
- // ITs always true;in the sense it automatically creates a new database name test.sqlite in the /usr/local/bin folder
- }
Please give some suggestions over this issue.
Thanks,
Vsh.Vshnu
[EDIT: code formatting, please use @-tags, not stars (*), Volker]
Hi Vsh.Vshnu,
Follow the SQLite examples given in Forum Nokia:
Creating an SQLite database in Qt [wiki.forum.nokia.com]
Searching for data in a database in Qt [wiki.forum.nokia.com]
Best regards,
Leon
Hi Vsh.Vshnu,Follow the SQLite examples given in Forum Nokia:
Creating an SQLite database in Qt [wiki.forum.nokia.com]
Searching for data in a database in Qt [wiki.forum.nokia.com]Best regards,
Leon
Hi leon.anavi,
My problem is different.Its becasuse i am not able to open a existing sqlite database inside project main folder.
I want the sqlite files to be inside my application package file??
the target path of your app is /usr/local/bin, the path of your db is test.sqlite – so the complete path is /usr/local/bin/test.sqlite. Sounds quite ok for me (in regard to the setup, a database file in /usr/local/bin is a no-go!).
Do you have a test.sqlite that actually is packed in your setup?
And be aware, the packing options are Symbian only!. It is ignored for any other operating systems, including Meego! It is for reason, that Matze5590 has put them into the symbian scope!
Hi Volker,
Its simply
QString dbName=“test.sqlite”;Iam developing for meego in windows developement enviorment using Qt creator
Try to use the absolute path. You can get the file path of the application executable using QCoreApplication::applicationFilePath [doc.qt.nokia.com]
Cheers,
Leon
You must log in to post a reply. Not a member yet? Register here!




