Important: Please read the Qt Code of Conduct -

Trouble with Connections

  • I am trying to send a signal from C++ to QML.
    It seems I have done everything correct according to the documentation, however the signal is never received.

    I have the C++ object as a context property:

        context->setContextProperty("midiInterface", &midiInterface);

    have defined a signal in the MidiInterface class:

        void updateTriggered();

    And here's the connection:

        Connections {
            target: midiInterface
            onUpdateTriggered: {
                console.log("trigger update received")

    When the signal is emitted which I have verified through the debugger, the function is not called and there is no console output.

    Can't seem to find any documentation on why this may be happening.

  • Lifetime Qt Champion

    Are you sure that syntax works when its a c++ signal ?
    The docs says
    "A Connections object creates a connection to a QML signal."

    Anyway, I might just have over complicated it using the method
    section "Emitting a signal from C++ and listening to it from QML"

    if "onUpdateTriggered:" can in fact auto bind, its much more elegant :)

  • Hey, thanks for the response,

    I got that from this doc and a few stack overflows:

    Right at the bottom.

  • Lifetime Qt Champion

    You are right. it does say
    "ApplicationData has a signal named dataChanged()"
    and you even followed the naming exactly.

    So i assume your code is very close to the sample except other names?

  • Yes, just the names are different.

  • Also, I can see using your method, but I have no clue how I would get to the QML object

  • Lifetime Qt Champion

    I just tested the sample project and it worked.. :)
    So there must be something a little bit off some place in your code or something else.

    Test project

  • Have you registered it? For cpp instanced objects I register mine with:


  • I have it able to receive the signal if I put the connection in the top level Window qml. The qml object that needs the signal is nested a bit down in the hierarchy. Is this a know behavior?

  • So it seems like nothing is received down the hierarchy from the main window. I have used the Connections inside my Window qml and it's triggered fine. Trying to pass a signal from the Window down to the Component using QML and a Connection object inside the Component fails.

    So the components are inside a stack view. They are Component classes that contain a rectangle. The signal needs to happen within these components. Don't know if it matter, but these are not the initialItem of the StackView. I can get some code together if desired.

  • Moderators

    @Jpraccio I think, my knowledge is limited here, that that behaviour depends heavly on how you marry your cpp class and your qml root file.

    if for example you use qmlRegisterType<MyClass>("MyClass",1,0, "mClass"); than you can create an instande in each qml file you import myclass in, and can use Connect and signal slots there easily enough.

    If you create it as a fixed class and register it as a rootContext() / ContextProperty than you should be able to access it everywhere in your qml files.

    MyClass mClass;
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("MyClass", &mClass);
    //any qml file
        MyClass.onMySignal: console.log("SIGNAL!!!")
    //The actual signal in MyClass is named: mySignal
    //I believe the "on" prefix is needed

  • I have the c++ class working at this point, I can send a signal to the window qml. Now trying to send a signal into the qml objects from the window. It seems these specific qml components just can't receive them. It looks like this:

    // Window qml
    Window {
        id: mainWindow
        signal mySig()
        Connections {
             target: myCpp
             onAction: {
                  // this works
       StackView {
           initalItem: itemA
           ItemA {
              // this has a connection that works
         ItemB {
             // this won't receive the above signal
    // ItemB qml
    Component {
         Rectangle {
             Connections {
                 target: mainWindow
                 onMySig: {
                      // nothing happens here
                      // regardles of using the cpp signal or the qml signal

  • I made some changes that forced the stack view to transition and got a new error:

    QQmlEngine: Illegal attempt to connect to Chord(0x112847200) that is in a different thread than the QML engine QQmlApplicationEngine(0x7ffeefbfe1e0.

    Is it possible this is a threading issue of some sort? I am not intentionally spawning any threads myself

  • Solved by pushing ItemB onto the stack view.

Log in to reply