Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.8.0
-
None
-
Windows 7
Description
Short summary
QDeclarativeItem has implicitWidth and implicitHeight declared with Q_PROPERTY( ... REVISION 1)
With the following class "ObjectItem" it's inherited properties implicitWidth and implicitHeight can not be accessed from QML:
class ObjectItem : public QDeclarativeItem
{
Q_OBJECT
};
Long Description
In 4.8.0 rc1 there is an issue where QML extention c++ classes which are Q_OBJECT's do not expose Q_PROPERTY( ... REVISON 1 ) properties to the QML context.
There is a workaround that further reveals the issue, declare a QML extention c++ class that IS NOT a Q_OBJECT and register that with qmlRegisterType< X, 1 >. Then QML can access the Q_OBJECT derived classes REVISON 1 properties.
Below example main.cpp that exhibits the issue:
------------------------------------------
#include <QtDeclarative>
class WorkaroundItem : public QDeclarativeItem {};
class ObjectItem : public QDeclarativeItem
{
Q_OBJECT
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
qmlRegisterType< ObjectItem, 1 >( "MyQML", 1, 0, "ObjectItem" );
/* qmlRegisterType< WorkaroundItem, 1 >( "MyQML", 1, 0, "WorkaroundItem" ); */
QDeclarativeView view( QUrl( "main.qml" ) );
view.show();
return app.exec();
}
------------------------------------------
If 'main.qml' contains the following:
import MyQML 1.0;
ObjectItem
{
width: implicitWidth * 0.25
height: implicitHeight * 0.25
}
---------------------------------------
The following console output is obtained:
file:///.../main.qml:6: ReferenceError: Can't find variable: implicitHeight
file:///.../main.qml:5: ReferenceError: Can't find variable: implicitWidth
If the commented registration of WorkaroundItem is uncommented then no ReferenceError is reported (and the binds function as expected).
Further note, if ObjectItem is registered with no revison information:
qmlRegisterType< ObjectItem >( "MyQML", 1, 0, "ObjectItem" );
and the WorkaroundItem is uncommented then NO ReferenceErrors are reported; however if WorkaroundItem is registered without revision information then ReferenceErrors ARE reported.