Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Passing parameters to class inherited from QQuickPaintedItem

    QML and Qt Quick
    2
    6
    1025
    Loading More Posts
    • 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.
    • defs
      defs last edited by

      I have my own class inheriting from QQuickPaintedItem, which I use to draw some stuff at qml. I register it with function qmlRegisterType from main.cpp and it works fine, but I have to pass on to it one argument (object which is created in main.cpp file), because I want to expose some properties from this object to qml with setContextProperty function. How to do that?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        What about a simple setter ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • defs
          defs last edited by

          Yeah, but how to access to instance of class inherited from QQuickPaintedItem?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Can you show how you are currently using that class ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • defs
              defs last edited by defs

              Yes, I would like to access to object of Camera class, but don't know how, 'cos qml make this object and don't know how to access it from main.cpp.

              #include <QGuiApplication>
              #include <QQmlApplicationEngine>
              
              #include <QQmlContext>
              
              #include <QtQuick/QQuickView>
              #include <QObject>
              
              #include "camera.h"
              #include "serial.h"
              
              int main(int argc, char *argv[])
              {
                  Serial serial;
              
                  QGuiApplication app(argc, argv);
              
                  qmlRegisterType<Camera>("CameraMod", 1, 0, "Video");
              
                  QQuickView view;
                  view.setResizeMode(QQuickView::SizeRootObjectToView);
              
                  view.engine()->rootContext()->setContextProperty("serial", &serial);
                  view.setSource(QUrl("qrc:///main.qml"));
              
              
                  view.showFullScreen();
                  //view.show();
              
                  return app.exec();
              }
              
              
              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                One thing: QGuiApplication should be the first thing you create in your application. It sets up Qt's internal to work properly. You better move your Serial object creation after app.

                As for getting access to your QML object, see the Interacting with QML Objects from C++ chapter in Qt's documentation.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post