[SOLVED] Data file in resources is not recognised.
-
Hi,
I have problem with resource file under Windows 8.1. The resource file is very simple:
@<RCC>
<qresource prefix="/">
<file>data/eu_states.dta</file>
</qresource>
</RCC>
@The configuration file is:
@#-------------------------------------------------
Project created by QtCreator 2014-05-14T10:55:59
#-------------------------------------------------
QT += core
QT -= gui
TARGET = resources1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = appSOURCES +=
resources1.cppRESOURCES +=
my_resources.qrc
@The program is as follow:
@
#include <QCoreApplication>
#include <QtCore>
#include <iostream>
using namespace std;int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);try { QFile istr(":/data/eu_states.dta"); if (istr.open(QIODevice::ReadOnly)) { QTextStream in(&istr); while (!in.atEnd()) { cout << in.readLine().toStdString() << endl; } istr.close(); } else throw QString("%1 (%2).").arg(istr.error()) .arg(istr.errorString()); } catch(QString& err) { cout << "(RESOURCES1)ERROR: " << err.toStdString() << endl; } return a.exit();
}
@The program displays:
(RESOURCES1)ERROR: 5 (Unknown error).
Any idea what is wrong in this code or perhaps it is a bug in Qt?
Grzegorz -
Hi,
you misse Q_INIT_RESOURCE in the main before use resources
-
Thanks a lot. It works now!
BR, Grzegorz
-
PLease, add [SOLVED] to the Thread title