Connecting to the default propertyChanged signal
-
I have a property called
brightness
and want to connect thebrightnessChanged
signal to a C++ slot. Documentation says that you can write anon<Property>Changed
signal handler, but does not explicitly say that apropertyChanged
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 anotherbrChanged
signal (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 ?
-
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 definebrightnessChanged
anyway, since that results in theDuplicate signal name
error). -
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.