Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-15724

Functions connected to signals using connect() cannot receive QObject* values

    XMLWordPrintable

Details

    Description

      If a signal emits a QObject* and the signal is connected to a function using connect(), the QObject* parameter is received as a QVariant rather than an object.

      Given this code:

      Rectangle {
          id: rect
          width: 200; height: 50
      
          function myFunction(mouse) {
              console.log("In function:", mouse, mouse.x)
          }
      
          MouseArea {
              id: area
              anchors.fill: parent
              onClicked: {
                  console.log("In handler:", mouse, mouse.x)
              }
          }
      
          Component.onCompleted: {
              area.clicked.connect(myFunction)
          }
      }
      
      

      When the MouseArea is clicked, the output is:

      In handler: QDeclarativeMouseEvent(0x7fff5fbfdb10) 108
      In function: QVariant(QDeclarativeMouseEvent*) undefined
      

      Since the 'mouse' object is received as a variant by myFunction(), none of the MouseEvent properties can be read.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            aakenned Aaron Kennedy
            bealam Bea Lam (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes