Uploaded image for project: 'Qt for MCUs'
  1. Qt for MCUs
  2. QTMCU-221

The generated code from qmltocpp is different from what's written in QML

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • Qt for MCUs 2.5
    • Host Tools, QML
    • None
    • All

    Description

      *I have attached the project and the generated C++ code by qmltocpp, respectively, "Buttons.zip" and "Buttons.dir.zip."

      What the sample application does is to present three CheckBoxes and a Button.

      When the user clicks on the Button, the application outputs the number of checked CheckBoxes, like so:

       

      import QtQuick
      import QtQuick.Controls
      Rectangle {
          width: 480; height: 272
          Column {
              CheckBox {
                  id: checkbox1
                  text: checked ? "checked" : "unchecked"
              }
              CheckBox {
                  id: checkbox2
                  text: checked ? "checked" : "unchecked"
              }
              CheckBox {
                  id: checkbox3
                  text: checked ? "checked" : "unchecked"
              }
              Button{
                  text: "Calculate"
                  property int numChecked: 0
                  onClicked: {
                      numChecked = checkbox1.checked ? 1 : 0
                                 + checkbox2.checked ? 1 : 0
                                 + checkbox3.checked ? 1 : 0;
                      console.log("The number of checked checkboxes = " + numChecked);
                  }
              }
          }
      }

      The issue is, even when more than 1 CheckBoxes are checked, the application always outputs The number of checked checkboxes = 1.

       

      When none of the CheckBox is checked, it properly outputs The number of checked checkboxes = 0.

       

      I checked the concerning part of the generated code(
      void Buttons::button_onClicked_bindingFunctor::operator()() const in Buttons.cpp), and found out that the operations were wrong, as in it always adds 1 to 0, therefore, the application cannot output the value more than 1, even when more than 1 CheckBoxes are checked.

      Attachments

        1. Buttons.dir.zip
          1.21 MB
        2. Buttons.zip
          7.47 MB
        3. image-2023-10-01-20-13-45-372.png
          image-2023-10-01-20-13-45-372.png
          29 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tonyl Tony Leinonen
            mikio_hirai Mikio Hirai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes