Solved Can't load text file from .qrc
-
I've created an xml file that I'd like to be able to load from a .qrc file, but it's not working for some reason.
My qrc file is in
resources/mainresources.qrc
and I seem to be able to load icon images from it fine. For example,QIcon(":/icons/toolBrushVector.svg")
can be used to draw an icon.I've created a file called mainmenu.xml and placed it under resources/. I then added an entry to the qrc index:
</qresource> .... <file>mainmenu.xml</file> </qresource>
I then attempt to load the file into a string like this:
QFile file(":/mainmenu.xml"); QTextStream in(&file); QString xmlStrn = in.readAll(); file.close();
Unfortunately,
xmlStrn
keeps being set to "". What can I do to load my xml file? -
Looks like the problem wasn't with the qrc. I needed to load the text like this:
QFile file(":/mainmenu.xml"); file.open(QIODevice::ReadOnly); QString xml = file.readAll(); file.close();
-
Looks like the problem wasn't with the qrc. I needed to load the text like this:
QFile file(":/mainmenu.xml"); file.open(QIODevice::ReadOnly); QString xml = file.readAll(); file.close();
-
@kitfox You can use QTextStream, but you have to open the file first:
QFile file(":/mainmenu.xml"); if (data.open(QFile::ReadOnly)) { QTextStream in(&file); QString xmlStrn = in.readAll(); file.close(); }