Models
Most models are defined on the C++ side of the application as they reflects state of the player or the medialibrary. The general principle for creating QML model from C++ is explained in Qt documentation.
Dependency injection
Qml objects don't have constructor per se, a more typical approach is to pass the context of the object by injecting it in the object properties.
beware that property assignation is not atomic, if your model requires multiple property to be set, you must ensure manually that all property have been provided. Some typical object that can be injected in models are MainCtx to access most application settings, or MediaLib to access the Medialibrary
class MyModel : public QObject
{
Q_PROPERTY(MainCtx* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged FINAL)
///....
};
MyModel {
ctx: MainCtx
}
injecting global objects
Some objects can be made accessible globally to the application, for this prefer
registering the class as a singleton using qmlRegisterSingletonType
instead of
creating context properties. The registration should be made in along with the
other type registration in the MainUI class
see:
- maininterface/mainui.cpp
god object Single Store
the MainCtx object is the typical entry point for the QML to access the application state. it allows to retrieve most vlc objects (the vlc_object)
At moment the structure is mostly flat, properties are directly accessible as
MainCtx.property