[Solved] Error: forward declaration of 'class QQmlContext'



  • Hi guys

    I'm playing with QML/C++ integration and now I'm trying to set context property as described here http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-contextproperties.html

    So my code looks like this
    @
    #include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"
    #include <QDateTime>

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

    QtQuick2ApplicationViewer viewer;
    viewer.rootContext()->setContextProperty(QStringLiteral("somedata"), QDateTime::currentDateTime());
    viewer.setMainQmlFile&#40;QStringLiteral("qml/TestQML/main.qml"&#41;&#41;;
    viewer.showExpanded();
    
    return app.exec&#40;&#41;;
    

    }@

    I've just added line 10 to the project generated code
    @viewer.rootContext()->setContextProperty(QStringLiteral("somedata"), QDateTime::currentDateTime());@

    But unfortunately I've got this error
    ../TestQML/main.cpp:10:25: error: invalid use of incomplete type 'class QQmlContext'
    In file included from ../Qt5.1.0/5.1.0/gcc/include/QtQuick/QQuickView:1:0,
    from ../TestQML/qtquick2applicationviewer/qtquick2applicationviewer.h:14,
    from ../TestQML/main.cpp:2:
    ../Qt5.1.0/5.1.0/gcc/include/QtQuick/qquickview.h:52:7: error: forward declaration of 'class QQmlContext'

    Maybe someone came across with that before?


  • Lifetime Qt Champion

    Hi,

    You seem to be missing:

    @#include <QQmlContext>@



  • SGaist, thank you very very much. Last 10 years I spent with java and now I'm having a lot of fun with such stupid mistakes. Thank you for you time and have a nice day


  • Lifetime Qt Champion

    You're welcome ! A little learning curve... Happy coding :)


Log in to reply
 

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