Calling C++ method from QML before UI is shown
-
I have a C++ Class called "Colors" that offers a variety of properties which hold default colors for my app. This (singleton) is used by my QML and works fine.
I now want to change some of my default colors, so I will be calling the setters for Color's properties. However, if I do this from the Component.onCompleted for the main.qml then the entire interface will already have been drawn, and the user will see colors change onscreen.
I could obviously do this at the C++ level, but this is a class shared amongst many apps (so I can't make it permanent). If I make a descendant of Colors then my included static function (which registers the QML type and creates my singleton instance) will have to change for the new descendant class name. So doable, but not ideal. (I suppose I could use template, but I find those ugly to maintain).
Is there a signal my QML code can listen for that will allow me to update my Colors before the UI is drawn?
-
@ocgltd said in Calling C++ method from QML before UI is shown:
Component.onCompleted
This should help as this signal will be generated when the object is created & before rendering. What is the real issue if you use Component.onCompleted signal ?
-
I have a C++ Class called "Colors" that offers a variety of properties which hold default colors for my app. This (singleton) is used by my QML and works fine.
I now want to change some of my default colors, so I will be calling the setters for Color's properties. However, if I do this from the Component.onCompleted for the main.qml then the entire interface will already have been drawn, and the user will see colors change onscreen.
I could obviously do this at the C++ level, but this is a class shared amongst many apps (so I can't make it permanent). If I make a descendant of Colors then my included static function (which registers the QML type and creates my singleton instance) will have to change for the new descendant class name. So doable, but not ideal. (I suppose I could use template, but I find those ugly to maintain).
Is there a signal my QML code can listen for that will allow me to update my Colors before the UI is drawn?