TAGS :Viewed: 6 - Published at: a few seconds ago

[ Having difficulties with resource file in qt ]

when working with Qt Creator and developing my project, I've added to a resource file my txt file which contains some information. I thought that this file will be incorporated into exe file and I won't have to supply this file with my exe file. Now I'm running this exe file of my project and I'm getting info that the txt file couldn't be found (although everything works perfectly when run via Qt creator). Is there any way to make it work as so I don't have to provide this txt file with my program?
Resource file:

    <qresource prefix="/settings">

And I'm accessing it:

boost::filesystem3::ifstream fin("./Resources/setting_files/accepted_file_extensions.txt");

Answer 1

It works when you run in Qt Creator because the working directory is where you have your Resources folder. That Boost ifstream does not read the resource from your exe but the real file on the disk. Boost has no idea about Qt resources (nor should it). Instead, use QResource to read the resource data from your exe or use QFile to read it as if it was a file (by prefixing the path with :).