PDA

View Full Version : Debug resource system



pablow
29th January 2015, 14:24
Hi everyone

I have a problem using the resource system. I am not able
to display images linked into the resource system.

My project contains a resource.qrc and plugin.pro as follows:


<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/img">
<file alias="explore">resources/eye.png</file>
<file alias="export">resources/note_go.png</file>
<file alias="open">resources/delete.png</file>
<file alias="close">resources/add.png</file>
<file alias="options">resources/cog-edit-icon.png</file>
<file alias="reset">resources/arrow_undo.png</file>
</qresource>
</RCC>


ROOTDIR = $$_PRO_FILE_PWD_
SRCDIR = $$ROOTDIR/src
DESTDIR = lib
CUBE_H = $(CUBE_HEADERS)
CUBE_INC= $$CUBE_H/cube \
$$CUBE_H/cubew \
$$CUBE_H/gui

QCUSTOMPLOTDIR = $$ROOTDIR/3rd-party/qcustomplot

INCLUDEPATH += . .. $$CUBE_INC $$QCUSTOMPLOTDIR $$SRCDIR $$SRCDIR/widgets $$SRCDIR/backend
LIBS +=

QMAKE_CXXFLAGS += -std=c++11
QT += widgets printsupport

TEMPLATE = lib
CONFIG += plugin silent

RESOURCES = $$ROOTDIR/resources.qrc

HEADERS = $$files($$SRCDIR/*.h) \
$$files($$SRCDIR/widgets/*.h) \
$$files($$SRCDIR/backend/*.h) \
$$files($$QCUSTOMPLOTDIR/*.h)

SOURCES = $$files($$SRCDIR/*.cpp) \
$$files($$SRCDIR/widgets/*.cpp) \
$$files($$SRCDIR/backend/*.cpp) \
$$files($$QCUSTOMPLOTDIR/*.cpp)

target.path = $$PREFIX
target.CONFIG += no_check_exist

INSTALLS += target

TARGET = $$qtLibraryTarget(ExplorationPlugin)
OBJECTS_DIR = ./obj
MOC_DIR = ./moc
RCC_DIR = ./obj

I try to display images in a QIcon but it won't be displayed:


return QIcon( ":/img/explore" );

As you can see I am building a library as target.
I get no warnings/errors during the build. I also
compared the file size of the resulting library if I
include different sized images into the resource.qrc.
And - as expected - the size of the resulting library changes.
Therefore, I assume linking the resources into the library is fine.

Do you have any ideas what can be wrong?
Is there an option to show all available resource strings available
in the resource system?

Thanks in advance

anda_skoa
29th January 2015, 15:51
Is there an option to show all available resource strings available
in the resource system?

QDir can operate on the resource directory tree just like on the actual filesystem.
I.e.


QDir dir(":/");

would be the equivalent of the root directory.

Cheers,
_

pablow
29th January 2015, 16:15
Ok, thank you.
In fact, my resources are not included in the resource tree at all.
I only see the resources of the parent qt application using my library.

My library is a dynamic library. Therefore, there should be no need to
use Q_INIT_RESOURCE(), right?

pablow
30th January 2015, 09:13
Solved:

The problem was that both the main application and my library were using
"resources.qrc" as file name for the resource file. Apparently, that did not work.
I renamed the resource file in my library project and now it works.