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. Regarding Qml bindings
Forum Updated to NodeBB v4.3 + New Features

Regarding Qml bindings

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 202 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.
  • P Offline
    P Offline
    Praveen.Illa
    wrote on last edited by Praveen.Illa
    #1

    Hi Team,

    Why the below code is not working when clicked on cancel button ie., parameterValueText.text is not setting to value 0.

    I am assuming both val and parameterValueText.text are binded eachother. If I am wrong, please correct me

    Please find below steps
    Step 1: Edit a value in Text Input, for ex: 1
    Step 2: on Keyboard accepted, parameterValueText.onAccepted is called
    Step 3: Click on Save, saveBtn.onClicked is called
    Step 4: Click on Cancel, cancelBtn.onClicked is called but the parameterValueText.text is not changed to value 0.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Layouts 1.12
    import QtQuick.VirtualKeyboard 2.1
    
    ApplicationWindow {
        id: window
        width: 480
        height: 272
        visible: true
        title: qsTr("Keyboard")
    
        property int val: 0
    
        Column {
            Item {
                id: itemId
                height: 20
                width: window.width
    
                Rectangle{
                    width: 100
                    height: itemId.height
                    border.color:"black"
    
                    TextInput {
                        id: parameterValueText
                        text: val     //Assuming text and val are  binded ??
                        inputMethodHints: Qt.ImhDigitsOnly
                        anchors.fill: parent
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter
                        onAccepted:  console.log("Value = ", parameterValueText.text)
    
                    }
                }
            }
    
            Row {
                spacing: 10
                Button {
                    id: saveBtn
                    text: "Save"
                    onClicked: console.log("Save = ", parameterValueText.text)
                }
    
                Button {
                    id: cancelBtn
                    text: "Cancel"
                    onClicked: val = 0 //Why the value is not changing in parameterValueText.text ?
                }
    
            }
        }
    
    
        InputPanel
        {
            id:inputPanel
            y:parent.height
            width: window.width
    
            //Background for Virtual Keyboard
            Component{
                id:keyboardBackground
                Rectangle{
                    color:"#f4f6f3"//ScreenConfiguration.backGroundCanvas
                }
            }
            states: State {
                name: "visible"
                when: inputPanel.active
                PropertyChanges {
                    target: inputPanel
                    y: parent.height - inputPanel.height
                }
                PropertyChanges {
                    target: inputPanel
                }
            }
            transitions: Transition {
                from: ""
                to: "visible"
                reversible: true
                ParallelAnimation {
                    NumberAnimation {
                        properties: "y"
                        duration: 200
                        easing.type: Easing.InOutQuad
                    }
                }
            }
            Component.onCompleted: {
                keyboard.style.keyboardBackground = keyboardBackground;        // the keyboard background
            }
        }
    }
    

    main.cpp

    int main(int argc, char *argv[])
    {
        qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    

    sampleProject.pro

    QT += quick virtualkeyboard
    
    P 1 Reply Last reply
    0
    • P Praveen.Illa

      Hi Team,

      Why the below code is not working when clicked on cancel button ie., parameterValueText.text is not setting to value 0.

      I am assuming both val and parameterValueText.text are binded eachother. If I am wrong, please correct me

      Please find below steps
      Step 1: Edit a value in Text Input, for ex: 1
      Step 2: on Keyboard accepted, parameterValueText.onAccepted is called
      Step 3: Click on Save, saveBtn.onClicked is called
      Step 4: Click on Cancel, cancelBtn.onClicked is called but the parameterValueText.text is not changed to value 0.

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      import QtQuick.Layouts 1.12
      import QtQuick.VirtualKeyboard 2.1
      
      ApplicationWindow {
          id: window
          width: 480
          height: 272
          visible: true
          title: qsTr("Keyboard")
      
          property int val: 0
      
          Column {
              Item {
                  id: itemId
                  height: 20
                  width: window.width
      
                  Rectangle{
                      width: 100
                      height: itemId.height
                      border.color:"black"
      
                      TextInput {
                          id: parameterValueText
                          text: val     //Assuming text and val are  binded ??
                          inputMethodHints: Qt.ImhDigitsOnly
                          anchors.fill: parent
                          horizontalAlignment: Text.AlignHCenter
                          verticalAlignment: Text.AlignVCenter
                          onAccepted:  console.log("Value = ", parameterValueText.text)
      
                      }
                  }
              }
      
              Row {
                  spacing: 10
                  Button {
                      id: saveBtn
                      text: "Save"
                      onClicked: console.log("Save = ", parameterValueText.text)
                  }
      
                  Button {
                      id: cancelBtn
                      text: "Cancel"
                      onClicked: val = 0 //Why the value is not changing in parameterValueText.text ?
                  }
      
              }
          }
      
      
          InputPanel
          {
              id:inputPanel
              y:parent.height
              width: window.width
      
              //Background for Virtual Keyboard
              Component{
                  id:keyboardBackground
                  Rectangle{
                      color:"#f4f6f3"//ScreenConfiguration.backGroundCanvas
                  }
              }
              states: State {
                  name: "visible"
                  when: inputPanel.active
                  PropertyChanges {
                      target: inputPanel
                      y: parent.height - inputPanel.height
                  }
                  PropertyChanges {
                      target: inputPanel
                  }
              }
              transitions: Transition {
                  from: ""
                  to: "visible"
                  reversible: true
                  ParallelAnimation {
                      NumberAnimation {
                          properties: "y"
                          duration: 200
                          easing.type: Easing.InOutQuad
                      }
                  }
              }
              Component.onCompleted: {
                  keyboard.style.keyboardBackground = keyboardBackground;        // the keyboard background
              }
          }
      }
      

      main.cpp

      int main(int argc, char *argv[])
      {
          qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
      
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      

      sampleProject.pro

      QT += quick virtualkeyboard
      
      P Offline
      P Offline
      Praveen.Illa
      wrote on last edited by
      #2

      @Praveen-Illa

      This question was answered in another forum.
      Please refer below URL

      https://stackoverflow.com/questions/72601135/regarding-qml-bindings

      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