Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared Library QT Resource

Im having again another problem. This time, I have a .dll, a shared library that contains a .qrc (QT Resource) file, the problem is, that when I'm trying to access one of the resources of the library, it doesn't work. I tried implementing the:

Q_INIT_RESOURCE(resourcefilename)

and it stills not working. (It says that the "qInitResources_resourcefilename()" is not found.)

like image 671
Spamdark Avatar asked Aug 25 '12 00:08

Spamdark


People also ask

How do I add a resource file to Qt?

In the Location field, specify a location for the file. Select Add to create a . qrc file and to open it in the Qt Resource Editor. To add resources to the file, select Add > Add Files.

What is RCC in Qt?

The rcc tool is used to embed resources into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (. qrc) file.

What is QRC file in Qt?

RESOURCES = application.qrc. qmake will produce make rules to generate a file called qrc_application. cpp that is linked into the application. This file contains all the data for the images and other resources as static C++ arrays of compressed binary data.

How do I create a QRC file?

Click the Edit Resources button (first on the left) Click the New Resource File button (first on the left) Enter a file name (e.g. resources. qrc) and click Save.


2 Answers

Nevermind. I found the solution. The qInitResources_name() was not found. So, I created a function inside the shared library

int RmiLib::startResources(){
    extern int qInitResources_rmi();
    return qInitResources_rmi();
}

Then, on the main App, I called that function, and yay! It worked.

like image 56
Spamdark Avatar answered Sep 21 '22 06:09

Spamdark


I am going to assume that you are using Windows because you say you have a .dll

I just ran into this same problem that the function qInitResources_resourcefilename cannot be found. This function does indeed exist in the shared library if your library has a .qrc file (check the mapfile). The problem is that this function is not exported and so the linker does not find it while linking the main App. I added the function qInitResources_resourcefilename to the export table of the shared library as follows.

Add a new file to the shared library export.def

LIBRARY
EXPORTS
  qInitResources_resourcefilename

Add the following to your shared library .pro file

QMAKE_LFLAGS += /DEF:\"$${PWD}\\export.def\"
OTHER_FILES += \
    export.def

Your solution works around this problem because RmiLib::startResources is included in the export table.

I am using Windows 7, MSVC 2010, Qt 5.2.0

like image 42
eatyourgreens Avatar answered Sep 22 '22 06:09

eatyourgreens