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. QT doesn't want to load resource
Forum Updated to NodeBB v4.3 + New Features

QT doesn't want to load resource

Scheduled Pinned Locked Moved Unsolved General and Desktop
resourceloading imagesloadloadingqrc
2 Posts 2 Posters 2.4k Views
  • 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.
  • X Offline
    X Offline
    xLlama
    wrote on 23 Dec 2016, 14:59 last edited by xLlama
    #1

    I want to load a resource. This is my code:

        QFile file(":/images/loading");
        QByteArray dump = file.readAll();
        qDebug() << "contents: " << dump;
        qDebug() << "error status: " << file.error();
    
    

    But the output is:

    QIODevice::read (QFile, ":\images\loading"): device not open
    contents:  ""
    error status:  0
    

    .pro file:

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = Streamcloud
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    CONFIG += mobility
    MOBILITY = 
    
    DISTFILES +=
    
    RESOURCES += \
        images.qrc
    
    
    

    images.qrc file:

    <RCC>
        <qresource prefix="/images">
            <file alias="loading">loading.gif</file>
        </qresource>
    </RCC>
    
    

    alt text

    What did I do wrong?

    T 1 Reply Last reply 23 Dec 2016, 15:25
    0
    • X xLlama
      23 Dec 2016, 14:59

      I want to load a resource. This is my code:

          QFile file(":/images/loading");
          QByteArray dump = file.readAll();
          qDebug() << "contents: " << dump;
          qDebug() << "error status: " << file.error();
      
      

      But the output is:

      QIODevice::read (QFile, ":\images\loading"): device not open
      contents:  ""
      error status:  0
      

      .pro file:

      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = Streamcloud
      TEMPLATE = app
      
      
      SOURCES += main.cpp\
              mainwindow.cpp
      
      HEADERS  += mainwindow.h
      
      FORMS    += mainwindow.ui
      
      CONFIG += mobility
      MOBILITY = 
      
      DISTFILES +=
      
      RESOURCES += \
          images.qrc
      
      
      

      images.qrc file:

      <RCC>
          <qresource prefix="/images">
              <file alias="loading">loading.gif</file>
          </qresource>
      </RCC>
      
      

      alt text

      What did I do wrong?

      T Offline
      T Offline
      t3685
      wrote on 23 Dec 2016, 15:25 last edited by
      #2

      @xLlama

      You did not open your file for reading as indicated by the error messag "device not open".

      http://doc.qt.io/qt-5/qiodevice.html#open

      1 Reply Last reply
      2

      1/2

      23 Dec 2016, 14:59

      • Login

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