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. Qt property reset feature
Forum Updated to NodeBB v4.3 + New Features

Qt property reset feature

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 2.0k Views 2 Watching
  • 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    how is the RESET feature of a property called from QML?

    Q_PROPERTY(int counter READ counter WRITE setCounter RESET resetCounter)
    ...
    int counter() const;
    void setCounter(int counter);
    void resetCounter();
    ...
    

    In QML:

    MyObject.counter = 123
    // how can i call the reset function?
    

    Thanks!

    raven-worxR J.HilkJ 2 Replies Last reply
    0
    • beeckscheB beecksche

      Hi,
      how is the RESET feature of a property called from QML?

      Q_PROPERTY(int counter READ counter WRITE setCounter RESET resetCounter)
      ...
      int counter() const;
      void setCounter(int counter);
      void resetCounter();
      ...
      

      In QML:

      MyObject.counter = 123
      // how can i call the reset function?
      

      Thanks!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @beecksche
      simply assign undefined to the property

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • beeckscheB beecksche

        Hi,
        how is the RESET feature of a property called from QML?

        Q_PROPERTY(int counter READ counter WRITE setCounter RESET resetCounter)
        ...
        int counter() const;
        void setCounter(int counter);
        void resetCounter();
        ...
        

        In QML:

        MyObject.counter = 123
        // how can i call the reset function?
        

        Thanks!

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @beecksche said in Qt property reset feature:

        Hi,
        how is the RESET feature of a property called from QML?

        Q_PROPERTY(int counter READ counter WRITE setCounter RESET resetCounter)
        ...
        int counter() const;
        void setCounter(int counter);
        void resetCounter();
        ...
        

        In QML:

        MyObject.counter = 123
        // how can i call the reset function?
        

        Thanks!

        hi, that should be easy enought to do, you'll need the Q_INVOKABLE makro and you're fine to go:

        Q_PROPERTY(int counter READ counter WRITE setCounter RESET resetCounter)
         int counter() const;
         void setCounter(int counter);
        Q_INVOKABLE void resetCounter();
        

        To call the function from qml:

        MyObject.resetCounter();
        

        Edit: never mind, I read the question wrong, keep to what @raven-worx wrote x)


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0

        • Login

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