Important: Please read the Qt Code of Conduct -

MinGW32-make and Q_INIT_RESOURCE

  • I'm writing one of the examples supplied by Qt, FridgeMagnets, however I must compile it with g++ and use MinGW32-make.
    the initial statement Q_INIT_RESOURCE(fridgemagnets); doesn't work.
    it will not recognise the fridgemagnets.qrc file and do the things it's supposed to do.
    Must I add a magic word to my compilation/link commands??

    #include <QApplication>
    #include "DragWidget.h"
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
    //    QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
        DragWidget window;
    //#ifdef Q_OS_SYMBIAN
    //    bool smallScreen = true;
    //    bool smallScreen = QApplication::arguments().contains("-small-screen");
    //    if (smallScreen)
    //        window.showFullScreen();
    //    else;
        return app.exec();

    make file :
    Link objects obj/Debug/FridgeMagnetsd.o obj/Debug/DragLabeld.o obj/Debug/moc_DragLabeld.o obj/Debug/DragWidgetd.o obj/Debug/moc_DragWidgetd.o

    D:/MinGW/64/bin/g++ -Wl,-subsystem,windows -mthreads -o D:/Projects/FridgeMagnets/bin/Debug/FridgeMagnetsd.exe obj/Debug/FridgeMagnetsd.o obj/Debug/DragLabeld.o obj/Debug/moc_DragLabeld.o obj/Debug/DragWidgetd.o obj/Debug/moc_DragWidgetd.o -LD:/Qt64/qt-install/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -lQt5Widgets -lQt5Core -lQt5Gui

    D:\Projects\FridgeMagnets/src/FridgeMagnets.cpp:14: undefined reference to `qInitResources_fridgemagnets()'

  • Lifetime Qt Champion


    You should rather call Q_INIT_RESOURCE after creating your app object. Qt's internals are initialised after create an application object.

  • 'fraid not SGaist.

    The original code from the examples folder of my Qt64 installation has the call before the creation of the QApplication object.

    And I moved it to after the creation of the QApplication object -- it still fails for the exact same reasons.

  • Lifetime Qt Champion

    Which example is it ?

  • On my PC the example is located in :

  • Moderators

    You don't use that macro if your resources are in the application. Also you don't use it with dynamic libraries unless you're loading it at runtime. You need that macro when your resources are in a static library or in a plugin, or in a library that's being loaded at runtime.

  • thanks kshegunov, now we're getting somewhere.
    A "library that's being loaded at runtime" would be a DLL, wouldn't it?
    I load the resource ( = a list of words in a txt file) with :

    QFile dictionaryFile("dictionary/words.txt");

    Is this statement indicative of :
    A: a library being loaded at runtime or
    B: a static library or
    C: a plugin or
    D: a dynamic load library
    E: none of the above


  • Lifetime Qt Champion

    Answer E

    It shows you are trying to load a file from a relative path on the hard drive.

Log in to reply