Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Signal connect to C++ Signal
Forum Updated to NodeBB v4.3 + New Features

QML Signal connect to C++ Signal

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 433 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by fcarney
    #1

    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

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      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++");
        }
      }
      

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved