problem connecting Qt Quick Rangeslider with my c++ code



  • i am trying to connect my Qt Quick rangeslider with my c++ code to get the changed values
    using qt 5.8 .
    my code is as follows:

    import QtQuick 2.5
    import QtQuick.Templates 2.1
    import QtQuick.Controls 2.1
    import QtQml 2.2
    
    ApplicationWindow {
    
        width: 400
        height: 400
        visible: true
    
        Binding {
            target: object
            property: "value"
            value: rangeSlider.value
        }
    //    Binding {
    //        target: object
    //        property: "value"
    //        value: rangeSlider.second.value
    
    //    }
    
        RangeSlider {
            id: rangeSlider
            from: 0
            to: 100
            first.value: 0
            second.value: 100
    //        onValueChanged: print(value)
            //        onFirstChanged:  print(value)
            //        onSecondChanged: print(value)
    //        onFirstChanged: console.log("Change")
    //        onSecondChanged: console.log("Change")
    
            Connections {
                target: first
                onValueChanged: console.log("first.value changed!")
    //            onValueChanged: print(value)
            }
    //        Connections {
    //                target: first
    //                onValueChanged: console.log("first.value changed!")
    //            }
        }
    }
    

    #ifndef OBJECT_H
    #define OBJECT_H
    
    #include <QObject>
    #include <QApplication>
    #include <QtQml>
    
    class Object : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
    //    Q_PROPERTY(qreal value_2 READ value_2 WRITE setValue_2 NOTIFY valueChanged_2)
    public:
        explicit Object(QObject *parent = 0) :
            QObject(parent),
            mValue(0)
    //        mValue_2(0)
        {
        }
    
        qreal value() const {
            return mValue;
        }
    
    //    qreal value_2() const {
    //        return mValue_2;
    //    }
    
        void setValue(qreal value) {
            if (value != mValue) {
                mValue = value;
                emit valueChanged();
            }
        }
    
    //    void setValue_2(qreal value_2) {
    //        if (value_2 != mValue_2) {
    //            mValue_2 = value_2;
    //            emit valueChanged_2();
    //        }
    //    }
    signals:
        qreal valueChanged();
    //    qreal valueChanged_2();
    private:
        qreal mValue;
    //    qreal mValue_2;
    };
    
    #endif // OBJECT_H
    

    #include <QApplication>
    #include <QtQml>
    #include <QQmlApplicationEngine>
    #include "object.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    //    MainWindow w;
    //    w.show();
    
        QQmlApplicationEngine engine;
        Object object;
        engine.rootContext()->setContextProperty("object", &object);
        engine.load(QUrl(QStringLiteral("qrc:/RangeS.qml")));
    
        return a.exec();
    }
    
    

    want onValuechanged() for both slider handles ..

    thankx....


Log in to reply
 

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