QML Signal connect to C++ Signal



  • I have a signal that is emitted by a C++ object that is of "QItemSelectionModel" type. The signal I connect to is "selectionChanged". I have a slot connected to this signal in C++ and can verify that the signal is firing as it updates a C++ function that prints to the console.

    I am trying to connect a QML signal to this signal as the documentation says I can do:

    ListView {
      id: cell_list
      ~~~
    
      // update current selection
      signal selectionChanged
      onSelectionChanged: {
        console.log("selectionChanged")
      }
    
      Component.onCompleted: {
        cell_list.selectionChanged.connect(cells_selectionmodel.selectionChanged)
      }
    }
    

    I don't get any errors when running this code, but I never see "onSelectionChanged" fire.

    Edit:
    To clarify:

    • cell_list is the ListView in QML
    • cells_selectionmodel is the QItemSelectionModel exposed to QML


  • It would help if I were doing it right:
    https://stackoverflow.com/questions/29995250/how-can-i-listen-to-a-c-signal-from-qml

    So not doing the other QML and doing this works:

    Connections {
      target: cells_selectionmodel
      onSelectionChanged: {
        console.log("selectionChanged from C++");
      }
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.