Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QStandardPaths::standardLocations on iOs returns path that doesn't exist - intended behavior?
Forum Updated to NodeBB v4.3 + New Features

QStandardPaths::standardLocations on iOs returns path that doesn't exist - intended behavior?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schluchti
    wrote on last edited by
    #1

    Hi,

    I am using the following code snippet on iOs to open a sqlite3 database:

    SqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    QString path = QStandardPaths::standardLocations(QStandardPaths::DataLocation)[0];
    db.setDatabaseName(path + "/mydb.db");
    if(!db.open()){
        qDebug() << "Couldn't open database: " << db.lastError();
    }
    

    This always failed with the following error: QSqlError(-1, "Error opening database", "out of memory")

    It took me a long time to realize that it's because the QStandardPaths::standardLocations call returns a path that doesn't exist (yet).

    The following path gets returned in my case:
    /var/mobile/Containers/Data/Application/7E9912071-7A54-48A2-B166-51F5812160A67/Library/Application Support/myapp/myapp

    I verified that the path doesn't exist by calling dir.exists(); on the above path. After executing dir.mkpath(path); everything worked.

    My question is now: Is this really the intended behavior? I would have expected that QStandardPaths returns a path that's already valid and that I can immediatelly use.

    Want to read more about Qt?

    https://gympulsr.com/blog/qt/

    Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by Eddy
      #2

      Hi,

      When looking in the docs we can read this one is deprecated.

      QStandardPaths::DataLocation	
      Returns the same value as AppLocalDataLocation. This enumeration value is deprecated. 
      Using AppDataLocation is preferable since on Windows, the roaming path is recommended.
      

      Could you try using 'AppDataLocation'

      Returns a directory location where persistent application data can be stored. 
      This is an application-specific directory. To obtain a path to store data to be shared with other applications, 
      use QStandardPaths::GenericDataLocation. The returned path is never empty. 
      On the Windows operating system, this returns the roaming path. This enum value was added in Qt 5.4.
      

      It is mentioned this one is never empty. ;-)

      Eddy

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      2
      • ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by
        #3
            // Android: AppDataLocation works out of the box, iOS you must create the DIR first !!
            // Android: HomeLocationalso  works, iOS: not writable
            mDataRoot = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
           // guarantee that dirs exist
            bool ok = checkDirs(); // here I create all missing directories
        

        I'm always using QStandardPaths::AppDataLocation
        @Eddy is right: you can also use GenericDataLocation, but I always want to hide my data for other apps

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.9 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        S 1 Reply Last reply
        0
        • ekkescornerE ekkescorner
              // Android: AppDataLocation works out of the box, iOS you must create the DIR first !!
              // Android: HomeLocationalso  works, iOS: not writable
              mDataRoot = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
             // guarantee that dirs exist
              bool ok = checkDirs(); // here I create all missing directories
          

          I'm always using QStandardPaths::AppDataLocation
          @Eddy is right: you can also use GenericDataLocation, but I always want to hide my data for other apps

          S Offline
          S Offline
          Schluchti
          wrote on last edited by
          #4

          @ekkescorner If I got you right, then you are also creating the directory first on iOs, right?

          Want to read more about Qt?

          https://gympulsr.com/blog/qt/

          Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

          ekkescornerE 1 Reply Last reply
          0
          • S Schluchti

            @ekkescorner If I got you right, then you are also creating the directory first on iOs, right?

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #5

            @Schluchti said in QStandardPaths::standardLocations on iOs returns path that doesn't exist - intended behavior?:

            @ekkescorner If I got you right, then you are also creating the directory first on iOs, right?

            YEP

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.9 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved