Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to read the file created from another app using QStandardpath
Qt 6.11 is out! See what's new in the release blog

how to read the file created from another app using QStandardpath

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 2.1k Views 1 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    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,

    Pradeep Kumar
    Qt,QML Developer

    jsulmJ 1 Reply Last reply
    1
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      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 ...

      1 Reply Last reply
      4
      • Pradeep KumarP Pradeep Kumar

        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,
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

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

          Dheerendra
          @Community Service
          Certified Qt Specialist
          https://www.pthinks.com

          1 Reply Last reply
          2
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by
            #5

            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,

            Pradeep Kumar
            Qt,QML Developer

            jsulmJ 1 Reply Last reply
            0
            • Pradeep KumarP Pradeep Kumar

              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,

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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."

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                wrote on last edited by
                #7

                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.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                https://www.pthinks.com

                1 Reply Last reply
                5

                • Login

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