Important: Please read the Qt Code of Conduct -

How do I create a handler for a signal from my c++ object?

  • My QtQuick application is initialized as shown below from c++ main(). I have a signal from myObject, that I wish to handle in the QML pages but I can't figure out how. The last part of this guide ( touches on it, but doesn't work for me. I think it may be because the object is created from main() and not from within the QML.

        MyObjectType myObject;
        QQuickView *view = new QQuickView;
        view->rootContext()->setContextProperty("myObject", &myObject);

    Here is one thing I tried within my main QML item. I tried a bunch of other things too, but now I'm stumped. This gives me the warning 'Cannot assign to non-existent property "ghoztConnecting"' on the second line.

        signal signalToHandle()
        signalToHandle: myObject.onMySignal()
        onSignalToHandle: {

    I've also tried simply this, but it seems like it only recognizes the reference to myObject within the javascript code regions.

    myObject.onMySignal: {

    Any suggestions?

  • Moderators

    you need to go this way via the Connections element in QML:

    Connections {
        target: myObject
        onMySignal: {

Log in to reply