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]":http://qt-project.org/forums/viewthread/3495 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);
    viewer.setFlags(Qt::FramelessWindowHint);
    viewer.setMainQmlFile(QStringLiteral("qml/ubusell/main.qml"));
    viewer.showExpanded();

    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 ?
    Thanks!


  • 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
 

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