how to read the file created from another app using QStandardpath



  • Hi,

    i have 2 apps,
    from one app i have created the folder and text file.

    path  = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
      path.append("/Folder");
    
      QDir directoryPath(path);
    
      if (!directoryPath.exists())
      {
    
          directoryPath.mkpath(path);
    
          QDir::setCurrent(path);
    
          path.append("/file.xml");
    
          directoryPath.setCurrent(path);
          m_fileName = path;
      }
      else
      {
          path.append("/file.xml");
          m_fileName = path;
      }
    ```
    
    
    how can i access the same path from another app using Qstandardpath. if i use 
    the below code in another app,
    
      ```
    path  = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
      path.append("/Folder");
    
      QDir directoryPath(path);
    ```
    
    from another app , i am getting the return status as false. the directory does not exist.
    
    how can i get the access to the path from another app.
    
    Thanks,


  • Hi Pradeep Kumar,

    AppDataLocation is a location specific to an application, not global, so you should better use a global one like DocumentsLocation.

    There is one solution but it's look very like a hack ...
    Look at the path return by AppDataLocation and replace the app name with the one of the other app.
    Not recommended anyway ...


  • Moderators

    @Pradeep-Kumar I'm not even sure how this line can compile in your second app:

    path  = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
    

    QStandardPaths::standardLocations returns a QStringList and not a string.

    Another note:

    QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
    

    is dirty as you do not specify EXACTLY which of the QStringList entries you want to use. In your second app same code line could return other result.



  • Why do you want do that ? What is the requirement ?



  • hi,

    We have 2 app.
    From one app we are storing creating the folder and file.
    From another app we have to access the folder to store the files and read from the created file of another app.

    Thanks,


  • Moderators

    @Pradeep-Kumar In your case you should not use QStandardPaths::AppDataLocation as @dheerendra said. Use QStandardPaths::GenericDataLocation, http://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum says:
    "QStandardPaths::GenericDataLocation 11 Returns a directory location where persistent data shared across applications can be stored. This is a generic value. The returned path is never empty."



  • in addition to what @jsulm said, you can chose common location which is known to both apps or create the path & store in some place like DB or so. This way both the apps can read it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.