[SOLVED] Resources compilation from Qt Creator

  • Is there any way to get qrc_...cpp from Qt Creator or the only way is to go to RCC directly?

    And one more strange thing - if I start Qt Designer alone it shows the tab "Resources" next to "Actions". If I edit ...ui file from Qt Creator - there is no "Resources" tab. How it is so?

    And there is no visible icons in ToolBar when application is running.
    There are visible icons in Qt Designer.

    Executed qmake from the menu of Qt Creator - no changes.

    qmake-qt4 /home/user/Test.pro -r -spec linux-g++-64 CONFIG+=debug

    Ubuntu, Qt 4.7.4, Qt Creator 2.3.0



    Project created by QtCreator 2011-09-04T09:05:32


    QT += core gui

    TARGET = Fom_Data_Studio
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui



    <qresource prefix="/new/prefix1"> <------------------------------- /new/prefix1 looks strange for me

    [EDIT: code formatting, please wrap in @-tags, Volker]

  • I'm not quite sure about your problem but /new/prefix1 is the default prefix generated by Qt Creator if you do not enter a value by yourself. It can be freely changed or removed.

    The resource file is a simple XML file which can be edited out of Qt Creator using any text editor.

  • Thx for reply.

    1. My resource file in the post and it is obvious that it is XML. It must provide images for buttons, but it does not - this is THE ISSUE.
    2. Prefix - can it prevent from including *.png in application? Should I change / remove it?
    3. For me PREFIX should contain "images/" and file names should be without it. But I tried to do so - it does not work. Any ideas would be appreciated.

  • The file tags contain the paths relative to the directory where the qrc file lives. You must not remove the "images" part, as qrc cannot find the files then - we talk about physical files here.

    The prefix attribute of the qresource tag puts that files into a virtual subdirectory in the qrc file namespace ("qrc:/"). It is prepended to the paths of the file tags. You can remove the prefix (or set it to "/").

    At the moment, to access your images, would have to write

    QImage cabinetNew(":/new/prefix1/images/cabinet-new.png");

    See "The Qt Resource System":http://developer.qt.nokia.com/doc/qt-4.7/resources.html in the docs for an detailed explanation of the features and file format.

  • Resources are beeing accessed using the :/ prefix. The prefix specified in the qresource tag is optional. Only resources specifically listed in the RCC file are added - there are no wildcards like * or automated includes.
    // <qresource prefix="/new/prefix1">
    QIcon openIcon(":/new/prefix1/images/Actions-document-open-icon.png");

    // <qresource prefix="/">
    QIcon openIcon(":/images/Actions-document-open-icon.png");

    // <qresource>
    QIcon openIcon(":/images/Actions-document-open-icon.png");

  • Solved:

    1. I created RESOURCES file in Qt Creator and included icons there.
    2. In Qt Designer I selected an icon from RESOURCES (not from file).

    It all works now.

Log in to reply