Results 1 to 6 of 6

Thread: Storing and accessing a database with QT creator

  1. #1
    Join Date
    May 2018
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Storing and accessing a database with QT creator

    Hi

    I'm a newbie and am building an app that connect to a database. It all works fine when I use the following and use my own local file

    QString homeLocation = QStandardPaths::locate(QStandardPaths::HomeLocatio n, QString(), QStandardPaths::LocateDirectory);
    userFilePath = homeLocation+"DBDirectory";

    However, I need to store the database within the application.

    During development, I still need to be able to locate and access the database outside QTCreator so need to be able to locate it using file explorer for instance.

    I can't seem to be able to do it

    If I use the following, the directory gets created, but I can't locate it in my file system . . .

    temppath=qApp->applicationDirPath()+"/DBDirectory";

    QDir dir(temppath);
    if (!dir.exists()) {
    dir.mkpath(".");
    qDebug() << "NOT FOUND";
    }
    else
    {
    qDebug() << "FOUND";
    }

    equally, if I use the following the directory gets created too, but again I can't locate it . . . .

    temppath = "/DBDirectory";

    I apologise in advance if this is a naive question.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and accessing a database with QT creator

    What You see with this line :
    Qt Code:
    1. qDebug() << temppath;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and accessing a database with QT creator

    The correct path to store application specific data is QStandardPaths::AppDataLocation,QStandardPaths::Ap pLocalDataLocation or QStandardPaths::ConfigLocation depending on your needs.
    http://doc.qt.io/qt-5/qstandardpaths...dLocation-enum

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and accessing a database with QT creator

    Quote Originally Posted by ChristianEhrlicher View Post
    The correct path to store application specific data is QStandardPaths::AppDataLocation,QStandardPaths::Ap pLocalDataLocation or QStandardPaths::ConfigLocation depending on your needs.
    http://doc.qt.io/qt-5/qstandardpaths...dLocation-enum
    Not always. What about a portable application installed on pendrive or used by many users from the location on server ?

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and accessing a database with QT creator

    He did not said anything from a portable application. And therefore storing it in the application directory is plain wrong (the current user may not even have write access to this directory...)

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and accessing a database with QT creator

    I wrote nothing about access rights. I just wrote that the unconditional statement The correct path to store application specific data is is not always true.

Similar Threads

  1. Replies: 2
    Last Post: 8th November 2015, 00:46
  2. Replies: 2
    Last Post: 23rd September 2014, 16:23
  3. Replies: 3
    Last Post: 6th May 2009, 12:16
  4. Accessing xampp mysql database
    By synack in forum Newbie
    Replies: 8
    Last Post: 19th March 2009, 10:08
  5. Storing/retrieving a QIcon from a database
    By KShots in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2008, 03:55

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.