Important: Please read the Qt Code of Conduct -

Qt Quick 2.0 how to publish viewer class to QML [ SOLVED ]

  • Hi!

    I'm developing desktop app using Qt Quick 2.0 and I need to be able to access viewer class through QML in order to hide/minimise application ( I'm building app with custom window decorations ).
    I fallowed this thread "[Link]": but no luck.

    This is my main.cpp:

    #include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"

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

    QtQuick2ApplicationViewer viewer;

    // viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer);

    return app.exec&#40;&#41;;



    After I add this line to default main.cpp file:
    viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer);

    I get this error:
    In function 'int main(int, char**)':
    error: invalid use of incomplete type 'class QQmlContext'
    error: forward declaration of 'class QQmlContext'

    Any ideas ?

  • Moderators

    Add this to your includes:
    #include <QQmlContext>

  • It works now, Thank you so much sierdzio!

  • Moderators

    Pleasure. Happy further coding!

Log in to reply