Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Data file in resources is not recognised.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Data file in resources is not recognised.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    karhu44
    wrote on last edited by
    #1

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

    SOURCES +=
    resources1.cpp

    RESOURCES +=
    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      you misse Q_INIT_RESOURCE in the main before use resources

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karhu44
        wrote on last edited by
        #3

        Thanks a lot. It works now!

        BR, Grzegorz

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          PLease, add [SOLVED] to the Thread title

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved