Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User blackbird700's Avatar
    Join Date
    Jan 2009
    Posts
    26
    Hi
    I am building some app which uses sqlite database. When I create database, put it in my project folder, put DEPLOYMENT in .pro file (and write function for open database, of course) and build app for mobile phone - installer copies my database file on !:/data/app_name, but app won't connect to database...

    when I create database in memory of phone, I can normally run sql queries, but, when I close app - all changes are gone...

    Does anyone have idea how to connect to database file?

    here are some code snippets:
    Code:
    from my_app.pro
    QT += sql gui core
    
    data.sources = dat/*.dat
    data.path = !:/Data/my_app/
    DEPLOYMENT =  data
    Code:
    from my_app.cpp
    
    bool MainWindow::openDB()
    {
        //find sqslite driver
        db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName(QDir::rootPath() + "/my_app/data.dat");
        if (!db.open()){
            QMessageBox::critical(0, QString::fromUtf8("error!"), QString::fromUtf8("error"));
            return false;
        }else{
            QMessageBox::information(0, "Q'apla!", QString::fromUtf8("sucess"));
    
        return true;}
    }
    error strings are just for debugging, final application will have "normal" strings

    I call openDB() in main function, just before app.exec()

  2. #2
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    SQLite requires that the path be in "native' form. Use QDir::toNativeSeparators to transform the path into one that SQLite likes.

    Or, if you have no need to expose the DB externally, simply place it in the application private directory and specify no directory path at all.

  3. #3
    Registered User blackbird700's Avatar
    Join Date
    Jan 2009
    Posts
    26
    actually, I dont need to expose database externally, but I didn't know how to deploy it to app private directory.
    I assume, if I put database in app private directory, I'd need just write filename (it can basically be without extension)...

    What should I write in data.path (in project file), to put database in private dir?

  4. #4
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    data.path = .

  5. #5
    Registered User blackbird700's Avatar
    Join Date
    Jan 2009
    Posts
    26
    thank you!

Similar Threads

  1. Add existing Sqlite database to Qt project
    By santijdelatorre in forum Qt
    Replies: 31
    Last Post: 2011-05-15, 01:20
  2. DQuest - ORM framework for Qt/Sqlite
    By benlaud in forum [Archived] Qt SDKs and Tools
    Replies: 0
    Last Post: 2010-10-05, 05:13
  3. Replies: 2
    Last Post: 2010-06-02, 23:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved