I’m trying to create a kcm for grub2 with qml.
I have a KcmGrub2 Class and GrubData class. GrubData class contains the properties that will be accessed by qml.
But the problem here is that i believe i cannot access the GrubData object from KcmGrub2. Therefore it seems like i cannot change the state of apply button with the GrubData object.
So how do i register the object while being able to access it from the KcmGrub2 class?
Also how do i handle the state of apply button? point me to some code examples please. I did look through the code of some kcms but sadly i was unable to find it myself
There’s no need to manually create JavaScript objects (I don’t think that even works?) I recommend following the Qt QML C++ doc page which explains everything you need to know about registering singletons.
Also in your example, it looks like your passing the function itself into qmlRegisterSingleton You only posted a small snippet though.
As of what i read through the docs, i found that QQmlEngine Class | Qt QML 5.15.12 tells me i have to allocate the singleton object before the engine to make sure it outlives engine but in this scenario, I believe there is no way to allocate it before the engine. So how do i go around this issue. When i just tried that way without somehow allocating before engine, I get The registered singleton has already been deleted. Ensure that it outlives the engine.
I have no experiene with KCM development, but take a look through the Look and Feel KCM as it’s similar to your goal: a QML UI and a C++ model backing.
From what I understand:
Use KQuickAddons::ManagedConfigModule.
Don’t bother using a singleton, it’s not needed and it’s not what KCMs use anyway.
You can access the KCM object through org.kde.kcm. See the C++ Q_PROPERTYdeclared here and the QML access used here.
You can then handle creating QObjects on the C++ side, and then exposing them using Qt object properties like any other QML project.