c++ - How to include qrc data into Qt-based binary that was compiled using CMake -


i have big qt + third-party-library project try compile binary test program in machine. able make binary run (found necessary *.dlls , plugins), however, cannot figure out how include *.qrc data icons program. moment, binary cannot load icons, have buttons text.

the code structure of program follows:

  • root_folder
    • cmakelists.txt
    • program_folder
      • main.cpp
      • cmakelists.txt
      • data_folder / data.qrc , set of icons in svg format
      • other .cpp , .h files
    • lib_folder1
    • lib_folder2
    • ...

this how data.qrc file looks inside:

rcc> <qresource prefix="/">     <file>file-name.svg</file>     ... 

this how add resources program, inside cmakelists.txt of program_folder:

qt5_add_resources(img_rsc_added data_folder/data.qrc ) add_executable(${project_name} ${project_srcs} ${img_rsc_added} ) 

inside 1 of .cpp files of program_folder load icons:

static qicon icon(qpixmap(":/file-name.svg")); 

for icons, have class data{}; , inside class have set of methods, e.g., static const qicon& fileicon();. , in main code, when need use icon, call way: data::fileicon().

it works when compile , run source.

i prepared binary distribution of program, , how structured inside root folder:

  • imageformats
    • qsvg.dll
  • platforms
    • qwindows.dll
  • my_program.exe
  • qt5core.dll
  • other qt , 3rd-party-lib dlls

my question how , put data files? tried different locations, e.g., inside main folder, inside created data folder. , copied data had (svg file, qrc file), binary still cannot see resources. how solve it? or, common practice?

note, using cmake (not qmake) compile binary. using qt-5.4, on windows 7. let me know if question lacks details, add them. thanks!

the following command qt5_add_resources(img_rsc_added data_folder/data.qrc) makes source files binary data generate each resource provied qrc files(data.qrc in case) , list of resulting files stored in img_rsc_added variable. provided variable passed add_executable resources embedded in resulting binary.

next, actual problem: problem not distribution code itself. create , initialize qicons in static context , use qpixmap qpixmap requires qapplication , running not case static initialization context. proper fix move initialization of qicons local context(like class ctor or main function)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -