4

I want to compile a project with Qt in Visual Studio 2010. I have built all the prerequisite libraries and linked them in project properties.

I have also made the .cpp file from the project.qrc file (rcc) with the command below:

rcc project.qrc -name project -o qrc_project.cpp

Followed the instructions from http://www.qtcentre.org/archive/index.php/t-3425.html .

The project.coo file is produced with the following lines:

    int QT_MANGLE_NAMESPACE(qInitResources_project)()
    {
        QT_PREPEND_NAMESPACE(qRegisterResourceData)
            (0x01, qt_resource_struct, qt_resource_name, qt_resource_data);
        return 1;
    }
    
    Q_CONSTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qInitResources_project))

I have also included the .cpp file in the project. Although, I get the error below:

> Error 2611    error LNK2019: unresolved external symbol "int __cdecl
> qInitResources_project(void)" (?qInitResources_project@@YAHXZ)
> referenced in function main   D:\usr\Windows\main.obj project

Have I done something wrong with the rcc? Could anyone please help?

RAM
  • 2,257
  • 2
  • 19
  • 41
MTs
  • 199
  • 2
  • 19

4 Answers4

2

I solved my problem by producing a .rcc file and a .cpp file, both with the name of the project and not with the "qrc_" at the beginning of it. I have also linked both files on my project.

It seems that the compiler could not find the proper file, this is why i had the linking error.

The commands I used in order to produce the files mentioned above are:

  1. rcc -binary <path_to_qrc_file>.qrc -o <path_and_filename>.rcc

  2. rcc <path_to_qrc_file>.qrc -name <project_name> -o <path_and_filename>.cpp

MTs
  • 199
  • 2
  • 19
2

For someone using CMake:

you should enable AUTORCC to auto compile *.qrc files.

add_executable(project project.cpp project.qrc)

// enable autorcc and automoc
set_target_properties(project PROPERTIES AUTOMOC TRUE)
set_target_properties(project PROPERTIES AUTORCC TRUE)
maidamai
  • 712
  • 9
  • 26
0

I had found a really trivial workaround if nothing on SO works for you:

In VS, you can simply put your resource(images or icons) not in the library qrc file, but directly in the main project qrc file. Then, in library project, you can refer to the images using the path in main project, and there is even no need to call QT_INIT_RESOURCE.

I think this is not a good practice, but just note down for whoever tried all the solutions online and still not working.

Alan
  • 1,582
  • 1
  • 13
  • 11
0

If your project.qrc file is in the same project than the main and the main is not in a namespace, juste add Q_INIT_RESOURCE(project); in your main.

Elsewise define a function with just Q_INIT_RESOURCE(project); in it outside of any namespace in the library you have your project.qrc file. Call that function in your main.

Nicolas D.
  • 83
  • 5