Results 1 to 6 of 6

Thread: QT QML OfflineDatabaseAPI

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default QT QML OfflineDatabaseAPI

    I'm currently creating a program similar to Are you smarter than a 5th grader, where questions should be randomly chosen by the program.

    If ever I use the OfflineDatabaseAPI to store my questions, how do I save the database into a file where I can access it or how do I save the database so that when the application is installed to a mobile phone the database will still be accessible?

  2. #2
    Join Date
    Oct 2010
    Location
    India
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QT QML OfflineDatabaseAPI

    If you are using latest Qt Creator i.e. Qt SDK 1.2, you will see these lines in your project pro file.
    Qt Code:
    1. # Add more folders to ship with the application, here
    2. folder_01.source = qml/QtQuickDemo
    3. folder_01.target = qml
    4. DEPLOYMENTFOLDERS = folder_01
    To copy to clipboard, switch view to plain text mode 
    use this facility to package and export your database files..

    Else:
    Create a database file during the first startup of the application.. And if the database is already present then do nothing..

    This method is quite unwanted and indirect..

  3. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QT QML OfflineDatabaseAPI

    Hello,

    Yes, my .pro file looks like that. However, I really don't have any knowledge on how to package/export database files. I don't even know where the database file is

  4. #4
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QT QML OfflineDatabaseAPI

    Okay, so managed to stumble upon this.

    http://developer.qt.nokia.com/forums/viewthread/2093

    Basically, it helped out a lot. Although I have some questions for you pro's.

    1. The dude who made the thread in that link stated that he created three files.
    Qt Code:
    1. 1. Qt.md5(“mydb_name”).ini
    2. 2. Qt.md5(“mydb_name”).sqlite
    3. 3. Qt.md5(“mydb_name”) folder
    To copy to clipboard, switch view to plain text mode 

    I saw the .ini and the .sqlite file. But I didn't see that folder. Is that even required? And where do you declare these Qt.md5(“mydb_name”).ini? Inside your .cpp?

    2. I did exactly what he did
    Qt Code:
    1. QmlApplicationViewer viewer;
    2. viewer.engine()->setOfflineStoragePath(QString(customPath));
    To copy to clipboard, switch view to plain text mode 

    where my custom path is set to "qml/OfflineStorage"
    I created that qml/OfflineStorage path manually by navigating to the project folder and just creating a new folder, renaming it OfflineStorage and there's where I copied and pasted the .ini and .sqlite files I found on the default location. Is that right?

    Here's the structure of my project:
    Qt Code:
    1. \qml
    2. \Projectproj
    3. \main.qml
    4. \data.txt
    5. \OfflineStorage
    6. \Databases
    7. \9a41722cf143cae53004c21c7ec7b42f.ini
    8. \9a41722cf143cae53004c21c7ec7b42f.sql
    To copy to clipboard, switch view to plain text mode 

    I also made sure that my qrc file was updated.
    Qt Code:
    1. <!DOCTYPE RCC><RCC version="1.0">
    2. <qresource>
    3. <file>qml/Projectproj/data.txt</file>
    4. <file>qml/OfflineStorage/Databases/9a41722cf143cae53004c21c7ec7b42f.ini</file>
    5. <file>qml/OfflineStorage/Databases/9a41722cf143cae53004c21c7ec7b42f.sqlite</file>
    6. </qresource>
    7. </RCC>
    To copy to clipboard, switch view to plain text mode 

    Is that right? Do I include the Databases folder in the filepath?

    And when I ran the application, it didn't read the database stored in the default location (C:/Users/...) since i set the custom path to qml/OfflineStorage

    Here's my main.cpp
    Qt Code:
    1. QApplication app(argc, argv);
    2. QDeclarativeEngine engine;
    3. QString customPath = "qml/OfflineStorage";
    4. QmlApplicationViewer viewer;
    5. viewer.engine()->setOfflineStoragePath(QString(customPath));
    6. viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
    7. viewer.setMainQmlFile(QLatin1String("qml/Projectproj/main.qml"));
    8. viewer.showExpanded();
    9. return app.exec();
    To copy to clipboard, switch view to plain text mode 

    I wanna know what I'm doing wrong.

    EDIT:

    Well, I finally got it to work. The database opens. ALTHOUGH, how come I can't SAVE any data to my database?? When I use the default path -> C:/Users... etc, and I try to INSERT, it works. But when I set the customOfflineStoragePath, it does INSERT yes, but when I close the application and run it again, the database didn't change at all. How come?
    Last edited by bmn; 9th August 2011 at 20:17.

  5. #5
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QT QML OfflineDatabaseAPI

    Well, I finally got it to work. The database opens. ALTHOUGH, how come I can't SAVE any data to my database?? When I use the default path -> C:/Users... etc, and I try to INSERT, it works. But when I set the customOfflineStoragePath, it does INSERT yes, but when I close the application and run it again, the database didn't change at all. How come?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT QML OfflineDatabaseAPI

    Because resource files are read-only. Stop shooting blind and start reading the documentation instead of gathering incoherent code snippets from all over the web trying to stitch them all toghether to complete your school assignment.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.