title: How to expose C++ struct to QML?
body: <p>My aim is to show angle and length values at ui. However I am not even able to reach that variable from qml  file and forward it to the console. I have implemented <a href="https://forum.qt.io/topic/82325/best-way-to-access-a-cpp-structure-in-qml" rel="nofollow noreferrer">this topic</a> but no hope. I need help!</p>
  
  <p>controller.h</p>
  
  <pre><code>#ifndef CONTROLLER_H
  #define CONTROLLER_H
  
  #include &lt;QObject&gt;
  
  struct MyStruct {
      float angle;
      uint16_t length;
  };
  
  
  class Controller : public QObject
  {
      Q_OBJECT
  public:
  
       explicit Controller(QObject *parent = nullptr);
       MyStruct plate;
  
  };
  
  #endif // CONTROLLER_H
  
  
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;QGuiApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  #include &lt;controller.h&gt;
  #include &lt;QtQml&gt;
  #include &lt;qquickview.h&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  
      QGuiApplication app(argc, argv);
  
      QQmlApplicationEngine engine;
      const QUrl url(QStringLiteral("qrc:/main.qml"));
      QObject::connect(&amp;engine, &amp;QQmlApplicationEngine::objectCreated,
                       &amp;app, [url](QObject *obj, const QUrl &amp;objUrl) {
          if (!obj &amp;&amp; url == objUrl)
              QCoreApplication::exit(-1);
      }, Qt::QueuedConnection);
      Controller ctrl;
      QQmlContext *ctx=engine.rootContext();
      ctx-&gt;setContextProperty("controller", &amp;ctrl);
      engine.load(url);
  
      return app.exec();
  }
  
  
  </code></pre>
  
  <p>main.qml</p>
  
  <pre><code>import QtQuick 2.12
  import QtQuick.Window 2.12
  import QtQuick.Controls 2.0
  
  Window {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
      Button{
          onClicked: {
              console.log(controller.plate.length)
          }
      }
  
  
  }
  
  
  </code></pre>