Load file locally
-
@n34rt said in Load file locally:
so if I edit this file I don't need to re-add it to the .qrc
Actually, you don't...
That just need to runrcc
after file is modified, which is totally automatic in qmake, not sure how visual studio behaves. -
There are two ways to interpret the original query here:
- Can you use a file on the file system in place of a resource that is built into the executable? I addressed this.
- Is there a way to modify a file that is included in a Qt resource file and have that change automatically picked up so that
rcc
is executed? @Bonnie addressed this.
On my Linux box with qmake, the qrc file and any files listed in it are added to the Makefile as dependencies of the cpp file that
rcc
generates so that it is automatically re-run if any of them change.qrc_test.cpp: ../test/test.qrc \ /home/chrisw/Qt/5.15.2/gcc_64/bin/rcc \ ../test/test.png /home/chrisw/Qt/5.15.2/gcc_64/bin/rcc -name test ../test/test.qrc -o qrc_test.cpp
I am not sure how Visual Studio, I assume with a Qt plugin, handles these dependencies but that's the sort of thing you would need
-
@n34rt
If you need to read a file at runtime you need to know where that file is. If you are going to supply it as a separate file, rather than embedded into the executable as a resource, one possibility is to use QCoreApplication::applicationDirPath() to locate it relative to where the executable is. Another possibility is to use QStandardPaths to resolve standard locations.Note that this is talking about using files at runtime. Nothing to do with compile/development/VS time.
-
@n34rt
So you want to use a resource via a.qrc
for release, but not during development? Then use code to read from file at development runtime time. And/or maybe per @ChrisW67 change your makefile to omittest.png
as a dependency requiring runningrcc
while developing and get right at release time. But don't make a mistake!