Connecting to the default propertyChanged signal
-
I have a property called
brightnessand want to connect thebrightnessChangedsignal to a C++ slot. Documentation says that you can write anon<Property>Changedsignal handler, but does not explicitly say that apropertyChangedsignal 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 signalwhich 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
onBrightnessChangedhandler in QML which calls anotherbrChangedsignal (which then gets connected to the C++ slot), but that just seems sad. -
Did you define the brightnessChanged() in c++ or qml file ? From which component it is coming ?
-
brightnessis 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 definebrightnessChangedanyway, since that results in theDuplicate signal nameerror). -
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 ofbrightnessChanged(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.
-
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 ofbrightnessChanged(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.