Hi,

I'm trying to get an access to my c++ class from within QML. The idea is to run a function in C++ side when I press a rectangle area in QML. Also sending a signal from qml and catching it in c++ is an option. But all the examples I've found with google don't seem to work. I.e:

Qt Code:
  1. QDeclarativeView view;
  2. view.setSource(QUrl::fromLocalFile("main.qml"));
  3. view.rootContext()->setContextProperty("stopwatch", new Stopwatch);
  4. view.show();
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. import Qt 4.7
  2.  
  3. Rectangle {
  4. width: 300
  5. height: 300
  6.  
  7. MouseArea {
  8. anchors.fill: parent
  9. onClicked: {
  10. if (stopwatch.isRunning())
  11. stopwatch.stop()
  12. else
  13. stopwatch.start();
  14. }
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

this would give me an error: TypeError: Result of expression 'stopwatch.start' [undefined] is not a function.

Also one example of connecting signal/slot:

Qt Code:
  1. QDeclarativeView view;
  2. view.setSource(QUrl::fromLocalFile("main.qml"));
  3. QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());
  4. QObject::connect(rootObject, SIGNAL(someqmlfunc()), &this, SLOT(somecpluplusfunc()));
To copy to clipboard, switch view to plain text mode 

but conversion from QGraphicsObject to QObject is not possible.

Is there some working way to call a c++ function from within qml at the moment?