Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Make a QML Object immutable / locked?

Make a QML Object immutable / locked?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bits-n-Flips
    wrote on 2 Mar 2018, 23:22 last edited by Bits-n-Flips 3 Mar 2018, 01:17
    #1

    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?

    B 1 Reply Last reply 5 Mar 2018, 17:54
    0
    • B Bits-n-Flips
      2 Mar 2018, 23:22

      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?

      B Offline
      B Offline
      Bits-n-Flips
      wrote on 5 Mar 2018, 17:54 last edited by
      #2

      @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?

      1 Reply Last reply
      0
      • 6 Offline
        6 Offline
        6thC
        wrote on 6 Mar 2018, 00:32 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GrecKo
          Qt Champions 2018
          wrote on 6 Mar 2018, 08:28 last edited by
          #4

          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.

          1 Reply Last reply
          0

          1/4

          2 Mar 2018, 23:22

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved