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. (.json) file not found
Forum Updated to NodeBB v4.3 + New Features

(.json) file not found

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 301 Views
  • 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.
  • M Offline
    M Offline
    MaximBozek
    wrote on last edited by MaximBozek
    #1

    Hi,

    I am using a JSON file in my qt project (for translation). I put this file in a QT Recourse File. Here is the path: "qrc:/translation/translation.json". For some reason, selecting either "Copy Path" or "Copy URL" when right clicking the file and putting this into my project:

    std::string jsonFilePath = "qrc:/translation/translation.json";
    

    This gives me "file not found" errors.
    I am using the nlohmann/json library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths?

    JonBJ 1 Reply Last reply
    0
    • M MaximBozek

      Hi,

      I am using a JSON file in my qt project (for translation). I put this file in a QT Recourse File. Here is the path: "qrc:/translation/translation.json". For some reason, selecting either "Copy Path" or "Copy URL" when right clicking the file and putting this into my project:

      std::string jsonFilePath = "qrc:/translation/translation.json";
      

      This gives me "file not found" errors.
      I am using the nlohmann/json library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #3

      @MaximBozek said in (.json) file not found:

      This gives me "file not found" errors.

      You show a C++ std::string assignment. It is not possible that this line generates an error such as "file not found". Rather, later code which uses that string and tries to access a file via that path may give that error message at runtime.

      Qt resource paths (depending on context either qrc:/... or :/...) can only be accessed by suitable Qt code which treats this path as referring to an embedded resource. Anything else will try to actually access that as a file path, which is not going to be found.

      If you need to access the content of a resource outside of a Qt call which can read it, you need to use Qt code to temporarily copy it to a physical file (or the content as a byte array) and pass that to whatever external.

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Since your external library cannot access the virtual Qt file system you first have to copy the file to a location on your local disk.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • M MaximBozek

          Hi,

          I am using a JSON file in my qt project (for translation). I put this file in a QT Recourse File. Here is the path: "qrc:/translation/translation.json". For some reason, selecting either "Copy Path" or "Copy URL" when right clicking the file and putting this into my project:

          std::string jsonFilePath = "qrc:/translation/translation.json";
          

          This gives me "file not found" errors.
          I am using the nlohmann/json library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @MaximBozek said in (.json) file not found:

          This gives me "file not found" errors.

          You show a C++ std::string assignment. It is not possible that this line generates an error such as "file not found". Rather, later code which uses that string and tries to access a file via that path may give that error message at runtime.

          Qt resource paths (depending on context either qrc:/... or :/...) can only be accessed by suitable Qt code which treats this path as referring to an embedded resource. Anything else will try to actually access that as a file path, which is not going to be found.

          If you need to access the content of a resource outside of a Qt call which can read it, you need to use Qt code to temporarily copy it to a physical file (or the content as a byte array) and pass that to whatever external.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            MaximBozek
            wrote on last edited by
            #4

            ok guys thanks, I will just put the file in a physical location on my device

            1 Reply Last reply
            0
            • M MaximBozek has marked this topic as solved on
            • M MaximBozek has marked this topic as solved on

            • Login

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