Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML in C++ App error

QML in C++ App error

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 6.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schneidi
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schneidi
        wrote on last edited by
        #3

        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 ; )

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved