Can my app provide resources loaded by a Qt library?
-
For example, the Qt DataVisualization library loads a shader that’s specified in the library source code as “:/shaders/vertexSurfaceFlat”, and that shader is located in a shaders/ subdirectory in the source code directory. I would like my app that utilizes the library to “convince” the library to use an alternate shader, but I don’t want to modify library source code or library shaders. Is there a way my app can provide its own version of “:/shaders/vertexSurfaceFlat” for the library to load?
Thanks!
-
@Tom-asso said in Can my app provide resources loaded by a Qt library?:
Is there a way my app can provide its own version of “:/shaders/vertexSurfaceFlat” for the library to load?
A resource file is embedded into the built binary. A path like “:/shaders/vertexSurfaceFlat” tells Qt to use the embedded file.
If you want the library to load an alternate file, then the library must accept an alternate path. If the path is hard-coded into the library, then it cannot load an alternate file.
-
@Tom-asso said in Can my app provide resources loaded by a Qt library?:
So how does library source code specify an "alternate path" versus "hard-coded path"?
In my previous post, "alternate path" means "a path that is different from
:/shaders/vertexSurfaceFlat
".If the path is "hard-coded", it means that the path is written in the source code as a string literal. The opposite of "hard-coded" is "programmatic".
void openFiles(const QString &filePath) { QFile file1("hello.txt"); // Hard-coded path QFile file2(filePath); // Programmatic path // ... }
-
@JKSH - I see. And if the library code also specifies an "alias" for the resource, there is still no way around the absolute path? E.g. if the library's qrc file contains:
<qresource prefix="/shaders"> <file alias="fragment">shaders/default.frag</file>
Thanks!
-
Hi,
Just to be sure I understand you, you would like to somehow replace the shader loaded by Qt Datavizualisation with your own ?
-
@Tom-asso said in Can my app provide resources loaded by a Qt library?:
And if the library code also specifies an "alias" for the resource, there is still no way around the absolute path?
Nope. An alias is still a hard-coded path as it cannot be changed at runtime.