Make a QML Object immutable / locked?
-
Just curious --
Is there a way to make a QML object immutable.
For instance, if someone is using pyqt and changes a property in the QML object, could it be rejected or just not changed?I would be nice if Qt/QML had a flag or boolean for that so I could just go into the QML object in question in QtCreator and add it in.
If something like that doesn't exist, what would you suggest?
-
@Bits-n-Flips
No takers?
This is for specifically a text object that gets changed on the Python side. Is there any way to lock the text object in QML so that if Python (or C/C++) decides to modify a property in that Text object, it does not change? -
You could add whatever code you want in the set method. If you bind your QML text to the engine side - that's what it is. I'm not sure I understand.
Using a Q_PROPERTY as:
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)you'd just do the validation / custom work in setName? If it fails, don't update the value, don't emit nameChanged? Am I missing something.
-
Where is the Object declared? in c++/Python or QML?
Do you want a property binding to stop executing or just stop being able to modify properties imperatively?
Do you want to unlock it afterwards?
Can't you just not pass it to the c++/Python side?Generally it's already ill advised to modify a QML object from c++/Python (with findChildren and friends), so I'll advise you to just not do it.