QML in C++ App error



  • I have difficulties with QML in a C++ app.

    I tried the tutorial for "Using QML in C++ Applications".
    I just copied the code:

    @#include <QApplication>
    #include <QtDeclarative/QDeclarativeView>
    #include <QtDeclarative/QDeclarativeContext>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QDeclarativeView view;
    QDeclarativeContext *context = view.rootContext();
    context->setContextProperty("backgroundColor",
                                QColor(Qt::yellow));
    
    view.setSource(QUrl::fromLocalFile&#40;"main.qml"&#41;);
    view.show();
    
    return app.exec&#40;&#41;;
    

    }@

    but I get some error messages:

    debug/main.o: In function Z5qMainiPPc': /main.cpp:9: undefined reference to_imp___ZN16QDeclarativeViewC1EP7QWidget'
    /main.cpp:10: undefined reference to _imp___ZN16QDeclarativeView11rootContextEv' /main.cpp:12: undefined reference to_imp___ZN19QDeclarativeContext18setContextPropertyERK7QStringRK8QVariant'
    /main.cpp:14: undefined reference to _imp___ZN16QDeclarativeView9setSourceERK4QUrl' /main.cpp:17: undefined reference to_imp___ZN16QDeclarativeViewD1Ev'
    /main.cpp:17: undefined reference to `_imp___ZN16QDeclarativeViewD1Ev'
    collect2: ld returned 1 exit status
    mingw32-make[ 1 ]: *** [debug\C++_QML.exe] Error 1
    mingw32-make: *** [debug] Error 2

    I use the Qt Creator 2.0.8 snapshot because in the Creator 2.0 I can't create QML projects.

    Do you have an idea what could cause this problem ?



  • Please check that you use Qt library with enabled Declarative and have QT += declarative in your .pro file



  • Oh thanks the "QT += declarative" statement was missing in my .pro file.

    I know this is a greenhorn mistake but sometime I'll get even this ; )


Log in to reply
 

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