[SOLVED] Custom QML element init
-
I have a QML plugin, it exports the class "Window". This class has "width" and "height" properties. For some reason I have to recreate window to reflect any changes. I have a QML:
@import Graphic 1.0 // my plugin
Window
{
width: 800
height: 600
}@I know I could use QSize 800x600 to make it at once, but the given example represents the idea of separate properties (I have also fullscreen, etc,etc). How do I make my C++ class to automatically init() when, lets say "Component.onCompleted" happens? This is the code:
@import Graphic 1.0 // my plugin
import QtQuick 2.0 // for Component
Window
{
width: 800
height: 600
Component.onCompleted: init()
}@It basically does the job, but I want my interface to be more transparent, so user does not need to set this init() manually. Is this possible?
-
If your Window component is a subclass of QDeclarativeItem, you can override "QDeclarativeParserStatus::componentComplete":http://qt-project.org/doc/qt-4.8/qdeclarativeparserstatus.html#componentComplete
-
Hm, thank you very much, I'll now go and derive from QDeclarativeParserStatus. I didn't want QDeclarativeItem because I don't need all of those built-in utils for visualization, but this status-class is exactly what I need.
bq. QDeclarativeParserStatus provides a mechanism for classes instantiated by a QDeclarativeEngine to receive notification at key points in their creation. This class is often used for optimization purposes, as it allows you to defer an expensive operation until after all the properties have been set on an object.