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. Passing parameters to class inherited from QQuickPaintedItem
Forum Updated to NodeBB v4.3 + New Features

Passing parameters to class inherited from QQuickPaintedItem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • defsD Offline
    defsD Offline
    defs
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • defsD Offline
        defsD Offline
        defs
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • defsD Offline
            defsD Offline
            defs
            wrote on last edited by defs
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0

              • Login

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