Important: Please read the Qt Code of Conduct -

Change Property Qml inside Class

  • Hi Guys ,
    I want change the property value of a variable in class , But value does not change
    Why not change the value ?

    // Class.h
        QString loginsts;
        QString getLoginsts() const;
        void setLoginsts(const QString value);
    QString MyClass::getLoginsts() const
        return loginsts;
    void MyClass::setLoginsts(const QString value)
        loginsts = value;
    void MyClass::login(QString usr2,QString psw2)
        if( ... )
    // button onclicked qml
        property string loginsts : MyClass.getLoginsts()
            onClicked: {
                txt.text = loginsts
    //There is no value

  • Hi! If you want to use property bindings then you must declare your loginsts with Q_PROPERTY macro. This is well explained here.

Log in to reply