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. ComboBox text not getting changed.
Qt 6.11 is out! See what's new in the release blog

ComboBox text not getting changed.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    danild
    wrote on last edited by
    #1

    Hello,
    I have a ComboBox, I want to change the Text in the ComboBox when the Button clicks. But when I click the button it shows an error "qrc:/main.qml:930: TypeError: Cannot assign to read-only property "currentText"" . Please support.

    The following code is used for the Button.

    Button {
    id: idNextButtonUser
    anchors{
    top: idRectangleInsideUserRegister.top
    left: idPrevButtonUser.right
    topMargin: idRectangleInsideUserRegister.height/6
    leftMargin: idRectangleInsideUserRegister.width/8.5
    }
    background: POS_FunctionButton {
    text: "Next"
    width: idRectangleInsideUserRegister.width/8
    height: idRectangleInsideUserRegister.height/3
    onClicked: {
    _userMaster.next()
    idTxtFieldUserName.text= _userMaster.UserName
    idComboBoxRole.currentText= _userMaster.Role
    }
    }
    }

    JonBJ 1 Reply Last reply
    0
    • D danild

      Hello,
      I have a ComboBox, I want to change the Text in the ComboBox when the Button clicks. But when I click the button it shows an error "qrc:/main.qml:930: TypeError: Cannot assign to read-only property "currentText"" . Please support.

      The following code is used for the Button.

      Button {
      id: idNextButtonUser
      anchors{
      top: idRectangleInsideUserRegister.top
      left: idPrevButtonUser.right
      topMargin: idRectangleInsideUserRegister.height/6
      leftMargin: idRectangleInsideUserRegister.width/8.5
      }
      background: POS_FunctionButton {
      text: "Next"
      width: idRectangleInsideUserRegister.width/8
      height: idRectangleInsideUserRegister.height/3
      onClicked: {
      _userMaster.next()
      idTxtFieldUserName.text= _userMaster.UserName
      idComboBoxRole.currentText= _userMaster.Role
      }
      }
      }

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @danild
      QComboBox::currentText is a read-only property returning the current text. QComboBox::setEditText() is what you need to use to set the text, as per http://doc.qt.io/qt-5/qcombobox.html#setEditText.

      1 Reply Last reply
      2

      • Login

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