title: Qt - Connecting C++ and QML - ReferenceError: xxx is not defined
body: <p>I am new to Qt and am currently trying to connect a c++ part of my program with the qml part. The goal of th connection is to pass the currently selected item of a TreeView to qml (possibly via on_treeView_doubleClicked). Since that didnt work I tried all the suggested connections on here for a very basic programm, but I am always receiving the following error:</p>
  
  <p><code>file::/main.qml:10: ReferenceError: test is not defined</code></p>
  
  <p>This is the piece of my code regarding the connection:</p>
  
  <p>test.h:</p>
  
  <pre><code>#ifndef TEST_H
  #define TEST_H
  
  #include &lt;QObject&gt;
  #include &lt;QDebug&gt;
  
  class test : public QObject
  {
      Q_OBJECT
  public:
      explicit test(QObject *parent = nullptr);
      Q_INVOKABLE void testFunc();
  
  signals:
  
  public slots:
  };
  
  #endif // TEST_H
  </code></pre>
  
  <p>test.cpp:</p>
  
  <pre><code>#include "test.h"
  
  test::test(QObject *parent) : QObject(parent)
  {
  
  }
  
  void test::testFunc()
  {
      qDebug() &lt;&lt;  "Hello from C++!";
  }
  </code></pre>
  
  <p>mainwindow.cpp:</p>
  
  <pre><code>test testObj;
  QQmlApplicationEngine engine;
  ui-&gt;quickWidget-&gt;setSource(QUrl::fromLocalFile(":/main.qml"));
  
  engine.rootContext()-&gt;setContextProperty("test", &amp;testObj);
  </code></pre>
  
  <p>main.qml:</p>
  
  <pre><code>import QtQuick 2.0
  import QtQuick.Window 2.3
  
  Item {
      Timer{
          id: timer
          interval: 1000; running: true; repeat:true
          onTriggered:{
              console.log("ex")
              test.testFunc();
          }
      }
  }
  </code></pre>
  
  <p>I would be really thankful for any help (not only for the simple programm, but possibly for passing the currently selected item of my treeView). I know there a a couple suggestions in other threads, but they dont seem to work for me, so please dont mark this as duplicate.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Lucas</p>