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. problem connecting Qt Quick Rangeslider with my c++ code
Forum Updated to NodeBB v4.3 + New Features

problem connecting Qt Quick Rangeslider with my c++ code

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtquickcontrolqtqmlqtquick
1 Posts 1 Posters 751 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.
  • S Offline
    S Offline
    Swapnil_Shelke
    wrote on 29 Jun 2017, 05:49 last edited by
    #1

    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....

    1 Reply Last reply
    0

    1/1

    29 Jun 2017, 05:49

    • Login

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