title: What is the most formal way to invoke C++ code in response to a QML button?
body: <p>Using qt 5.5, qt quick controls 1.4 and the below qt creator boilerplate code: what is the most FORMAL way to invoke C++ code in response to a button (just debug text to screen)?</p>
  
  <pre><code>// main cpp
  #include &lt;QApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  
  int main(int argc, char *argv[])
  {
       QApplication app(argc, argv);
  
       QQmlApplicationEngine engine;
       engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  
       return app.exec();
  }
  </code></pre>
  
  <p>and the QML file inside the <code>qml.qrc</code>:</p>
  
  <pre><code>import QtQuick 2.5
  import QtQuick.Controls 1.4
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
  
      Button {
          id: add
          x: 248
          y: 222
          text: qsTr("add")
      }
  }
  </code></pre>
  
  <p>I am aware of <a href="https://stackoverflow.com/questions/24871237/qt-how-to-run-a-c-function-when-qml-button-is-clicked-using-qqmlapplication">this</a> as a possible answer but it looks a very complicated way to just hook a button to a code! If this is The Formal way to use Qt 5.5 and QML then this should be the answer.</p>