(.json) file not found
-
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 thenlohmann/json
library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths? -
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 thenlohmann/json
library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths?@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.
-
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.
-
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 thenlohmann/json
library for parsing the .json file. Could the issue be that non-qt libraries can't 'use' these types of file paths?@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.
-
ok guys thanks, I will just put the file in a physical location on my device
-
-