[Interest] How to handle test resources files, building with QMake?

Doogster thedoogster at gmail.com
Sat May 23 15:28:41 CEST 2020


Okay, I'm at the stage where I'm stuck and I need to ask for help here...

For the unit tests in my current project, I've prepared external files
that the tests would use. For example, a one-second silent MP3 file
with a certain set of tags. I have these in a resources/ folder,
versioned in the source tree.

I also chose to use QMake, not CMake, as my build system, because Qt
Creator's standard projects give you an out-of-the-box "make check" if
you use QMake, but not if you use CMake.

Now, in CMake, I can just copy the "test resources" folder (which
contains, among other things, the MP3) to the executable directory,
like this:

file(COPY resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}

I am completely stuck as to how to do this in QMake. The best thing I
could find is this:

"Copying files with qmake"
https://retifrav.github.io/blog/2018/06/08/qmake-copy-files/

I mean, that works, but it's obviously not as good as the CMake solution.

I also considered indexing the MP3 in a QRC file and using resource
paths. The problem is, I need the absolute path to that MP3 file (I'm
passing the path to a subprocess that the unit test creates), and that
really doesn't seem to be what Qt's resource system is for. I see the
code for getting those paths, here,

Getting paths of qrc files in Qt
https://stackoverflow.com/a/23844313/240515

And it's... clearly not as good as just doing it in CMake either.

Is the recommendation to switch to CMake, set and set the tests up to
run with ctest, as described here,

https://doc.qt.io/qt-5/qtest-overview.html#building-with-cmake-and-ctest

Or is there a good way to do this in QMake?


More information about the Interest mailing list