Important: Please read the Qt Code of Conduct -

[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:

    <qresource prefix="/">

    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 = app

    SOURCES +=


    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 ( {
            QTextStream in(&istr);
            while (!in.atEnd()) {
                cout << in.readLine().toStdString() << endl;
        else throw QString("%1 (%2).").arg(istr.error())
    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?

  • 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

Log in to reply