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. Proper access of buttons from ButtonGroup?
Forum Update on Tuesday, May 27th 2025

Proper access of buttons from ButtonGroup?

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

    Hi,
    in an application I create buttons and assign them to a ButtonGroup dynamically.

    In the ButtonGroup I would like use and modify properties of the button clicked.
    This works in the following MWE.

    However, the usage of "button.text" throws the message:
    Parameter "button" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.

    What is the proper way to fix this?

    MWE:

    import QtQuick 6
    import QtQuick.Window 2.15
    import QtQuick.Controls 6
    import QtQuick.Layouts 1.15
    
    ApplicationWindow {
        id: window
        width: 450
        height: 300
        visible: true
    
    ButtonGroup {
        id:btnGroup
    
        onClicked: {
            console.log("clicked:", button.text) //Throws message
        }
    }
    
    GridLayout  {
        columns: 2
        anchors.fill: parent
    
        // DUMMY BUTTONS, IN REALITY DYNAMICALLY CREATED
        Custom_btn {
            text: qsTr("Dummy1")
            ButtonGroup.group: btnGroup 
        }
        Custom_btn {
            text: qsTr("Dummy2")
            ButtonGroup.group: btnGroup 
        }
    
    }
    
    }
    

    Thanks!

    eyllanescE 1 Reply Last reply
    0
    • R robro

      Hi,
      in an application I create buttons and assign them to a ButtonGroup dynamically.

      In the ButtonGroup I would like use and modify properties of the button clicked.
      This works in the following MWE.

      However, the usage of "button.text" throws the message:
      Parameter "button" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.

      What is the proper way to fix this?

      MWE:

      import QtQuick 6
      import QtQuick.Window 2.15
      import QtQuick.Controls 6
      import QtQuick.Layouts 1.15
      
      ApplicationWindow {
          id: window
          width: 450
          height: 300
          visible: true
      
      ButtonGroup {
          id:btnGroup
      
          onClicked: {
              console.log("clicked:", button.text) //Throws message
          }
      }
      
      GridLayout  {
          columns: 2
          anchors.fill: parent
      
          // DUMMY BUTTONS, IN REALITY DYNAMICALLY CREATED
          Custom_btn {
              text: qsTr("Dummy1")
              ButtonGroup.group: btnGroup 
          }
          Custom_btn {
              text: qsTr("Dummy2")
              ButtonGroup.group: btnGroup 
          }
      
      }
      
      }
      

      Thanks!

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @robro Use

          ButtonGroup {
              id: btnGroup
              onClicked: function(button) {
                  console.log("clicked:", button.text);
              }
          }
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1

      • Login

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