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. Connecting to the default propertyChanged signal
Qt 6.11 is out! See what's new in the release blog

Connecting to the default propertyChanged signal

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 3.5k 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I have a property called brightness and want to connect the brightnessChanged signal to a C++ slot. Documentation says that you can write an on<Property>Changed signal handler, but does not explicitly say that a propertyChanged signal exists.

    If I try to add a signal brightnessChanged(int b) I get the error:

    Duplicate signal name: invalid override of property change signal or superclass signal
    

    which suggests that the propertyChanged signal exists. But if I try to connect to the brightnessChanged signal without declaring it in QML, I get

    QObject::connect: No such signal MyProject_QMLTYPE_11::brightnessChanged(int)
    

    So how can one connect to the default propertyChanged signal which apparently exists but somehow is not accessible? My current workaround is to have an onBrightnessChanged handler in QML which calls another brChanged signal (which then gets connected to the C++ slot), but that just seems sad.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      Did you define the brightnessChanged() in c++ or qml file ? From which component it is coming ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      1
      • vikramgV Offline
        vikramgV Offline
        vikramg
        wrote on last edited by vikramg
        #3

        brightness is a property in a QML file, and I want to connect the corresponding "Changed" signal to a C++ slot. I'm wondering if there is a way to reference this signal without explicitly defining it. (Note that there is no way to explicitly define brightnessChanged anyway, since that results in the Duplicate signal name error).

        1 Reply Last reply
        0
        • F Offline
          F Offline
          FKosmale
          wrote on last edited by
          #4

          The issue is that you've specified the wrong signature for the signal: The propertyChanged signals from QML don't have an argument, so you would need to connect to brightnessChanged() instead of brightnessChanged(int). In that case you would need to read the property value afterwards though.

          However, IMHO the cleaner solution is to us a onBrithnessChanged handler in QML instead, and to call the C++ slot from there.

          vikramgV 1 Reply Last reply
          1
          • F FKosmale

            The issue is that you've specified the wrong signature for the signal: The propertyChanged signals from QML don't have an argument, so you would need to connect to brightnessChanged() instead of brightnessChanged(int). In that case you would need to read the property value afterwards though.

            However, IMHO the cleaner solution is to us a onBrithnessChanged handler in QML instead, and to call the C++ slot from there.

            vikramgV Offline
            vikramgV Offline
            vikramg
            wrote on last edited by
            #5

            @FKosmale Ah, that explains it, thanks. The solution you propose is what I have implemented right now anyway; I had hoped there might be a more elegant way to do it. Thank you for clarifying.

            1 Reply Last reply
            0

            • Login

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