Results 1 to 3 of 3

Thread: Data base sqlite

  1. #1
    Join Date
    Nov 2014
    Posts
    12
    Qt products
    Qt5

    Default Data base sqlite

    Hi, how can I may to locate a data base in my project? I did the following. I adding a database witch situated on another disk in some folder:
    Qt Code:
    1. m_mydb = QSqlDatabase::addDatabase( "QSQLITE" );
    2. m_mydb.setDatabaseName( ":D/DB/EmployeeInfo.sqlite" );
    To copy to clipboard, switch view to plain text mode 
    But I want to locate it in the project folder. I have tried to add my data base to the project as a resource, first i have add a prefics /, in the project folder add a folder 'DB', in the qt appear a prefix '/' and a resource file DB/EmployeeInfo.sqlite
    I have telling a path:
    Qt Code:
    1. m_mydb.setDatabaseName( ":/DB/EmployeeInfo.sqlite" );
    To copy to clipboard, switch view to plain text mode 
    but it doesn't work, can you promt me?
    Thanks.

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Data base sqlite

    Hello,

    how should a database added as resource work? The resources are compiled into your program executable. Now assume you want to store some data into your database. This would imply that your program binary gets modified. This will not work.

    Storing the database in the program installation folder is possible and, if permissions are set right, it may work. However, operating systems have set up some rules where application specific data should be stored. I recommend following those rules.

    Best regards
    ars

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Data base sqlite

    If the database is only ever read-only, you could include it as a resource and then extract it to a temporary file before working on it.
    See QTemporaryFile::createNativeFile().

    If you need it read/write, you could extract it to a writable location, e.g. using QStandardPaths::writableLocation()

    Cheers,
    _

Similar Threads

  1. Update changes in QTableView to sqlite data base
    By nagabathula in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2011, 01:18
  2. Sqlite data base
    By sabbu in forum Newbie
    Replies: 14
    Last Post: 26th May 2011, 01:17
  3. Sqlite data base
    By sabbu in forum Newbie
    Replies: 2
    Last Post: 19th May 2011, 23:43
  4. Sqlite data base
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2011, 11:57
  5. Replies: 4
    Last Post: 19th December 2010, 06:15

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.