I am totally new to Qt and CMake. I have been doing a google test on my project (cmake and qt) for which I need to test the match of two images. I have a folder (outside the project directory) that contains these images. I want to access these images but not using the absolute path.
Something like this:
imread("home/../../test_images/img1.jpg")
But I want to set a common path for the images folder, so that anybody using my project later on will just have to set their test_image
folder path with respect to their machine, and need not make changes in the code.
I have tried the following so far.
1 . Tried adding a .qrc
resource file and tried to access the images. (This did not work since the images folder was outside the project directory.)
- Tried to set a Path variable in QT build environment settings.
None of the two methods worked.
What I am trying to accomplish: "To be able to avoid using an absolute path for the images I use and allow people trying to implement my code to only change the path at one place with their own test image locations."
Edit:
Looking for a way for setting a variable eg.IMG_PATH = "/path/to/image/files"
which can be set once and only the variable is used all over the executable files. So when someone clones my project they will just have to update the IMG_PATH
variable with the path to where their image files are located. So that now the IMG_PATH
variable gets updated everywhere in the remaining parts of the project.
UPDATE after answer given by @squareskittles :
My project Structure :
Project_Tester
|--CMakeList.txt
|--ExecutableScript.sh.in
|--test
|---CMakeList.txt
|---sample1.cpp
|---sample2.cpp
|---main.cpp
Sample 1,2 are c++ files with different testcases. The main.cpp runs all tests in the sample.cpp files, as below :
#include "gtest/gtest.h"
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
According to answer given by @squareskittles , How should i structure my main.cpp ,to be able to use/access the variable "IMAGES_PATH" in the files sample1.cpp and sample2.cpp ?
Is there a way to do it from QT Creator alone than running it from the terminal ?(by modifying .sh file contents)?
Or can the Path be set manually in the ExecutableScript.sh.in file ?
How can I access this variable that is set, from the other cpp files of the project ?