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!


  • Moderators

    @beecksche
    simply assign undefined to the property



  • @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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.