Using Qt 4.7.1
Compiling this code generates the following error: NOTIFY signal ‘ValueChanged’ of property ‘MyValue’ does not exist in class MyWidget.
- class MyWidget : public MyBaseWidget, public QAxBindable
- Q_PROPERTY(int MyValue READ getValue NOTIFY ValueChanged)
- //void ValueChanged(int);
Both the getValue method and ValueChanged signal are located in the base class.
Removing the slashes from the two last line makes the code compile.
Does Q_PROPERTY NOTIFY support using signals located in a base class? If no, are there any plans to add support and should the documentation (1) inform the developer of this limitation?
We have stable widget implementation with a number of methods and signals.
- class MyWidget : public Widget
- virtual ~MyWidget();
- void setFoo(int);
- int getFoo();
- void fooChanged(int);
At some point we needed to use this widget as an activeX (or activeQt) so we added the class below which did the trick. The Q_PROPERTY attributes act as an interface, therefore it made sense to have it as part of the MyWidgetActiveX class. Recently we used the NOTIFY attribute and discovered that it did not work like READ and WRITE attributes.
Is there a technical reason for this?
If you look at the code generated by the moc, you’ll see that there is only two changes when you add a NOTIFY field:
- the property flag changes
- the index of the notification signal is added to the meta data array.
Since the moc doesn’t really know which class your class inherits from, it can’t know the index of that signal in the base class. The existence of the signal would have to be tested dynamically at runtime rather than at compile time.
For the READ and WRITE fields, as the function names are used as is in the generated code, if the functions don’t exist, the compiler will generate an error, so the moc doesn’t have to do that check itself.