QScriptEngine: undefined reference to `recd::qInitResources_app()'



  • Hello,
    I'm following the example for the qScriptEngine from here:
    https://doc.qt.io/qt-5/qtscript-script-helloscript-example.html
    I've setup my project as follows: In the subdirs project my .pro file is that way:

    # commnon stuff for everyone
    include($$top_srcdir/recd2.pri)
    
    CONFIG += c++11
    
    TARGET = recd2
    CONFIG += console
    CONFIG -= app_bundle
    
    RESOURCES += \
        hello_app.qrc
    
    TEMPLATE = app
    
    SOURCES += main.cpp \
        sapplication.cpp \
    
    HEADERS += \
        sapplication.h \
    
    # redefine a Makefile INSTALL_PROGRAM variable. We want to instal wit SUID bit
    QMAKE_INSTALL_PROGRAM = install -m 4755 -p
    
    target.path = /usr/bin
    INSTALLS += target
    
    debug
    {
        message("Debug mode")
        QMAKE_CXXFLAGS += -DRECD_DEBUG
    }
    
    PRE_TARGETDEPS += \
        $$top_builddir/utils/libutils.a
    
    

    In my .qrc file I've declared the script that way:

    <RCC>
        <qresource prefix="/">
            <file>hello_app.js</file>
        </qresource>
    </RCC>
    
    

    The hello_app.js is in the same folder as .pro and .qrc files. So when I try to build the program I receive the message: : error: undefined reference to recd::qInitResources_hello_app(). From file with that content:

    SApplication::SApplication(int &argc, char **argv)
        : QCoreApplication(argc, argv),
          m_setup(false)
    {
        // proxy them to the plugins if needed
        s_argc = argc;
        s_argv = argv;
        if (temp_test_enable) {
            Q_INIT_RESOURCE(hello_app); // THE ERROR 
    
            QScriptEngine engine;
            QTranslator translator;
            translator.load("app_la");
            installTranslator(&translator);
            QString fname(":/scripts/app.js");
            QFile file(fname);
            file.open(QIODevice::ReadOnly);
            QTextStream strm(&file);
            QString content = strm.readAll();
            file.close();
            QScriptValue evVal = engine.evaluate(content, fname);
            if (evVal.isError()) {
                exit(-1);
            }
        }
    ....
    }
    

    So what am I doing wrong?



  • I've solved the problem: I've placed Q_INIT_RESOURCE in main and it compiled successfully.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.