Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetMapping of QRadioButtons
Forum Updated to NodeBB v4.3 + New Features

SetMapping of QRadioButtons

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 759 Views 2 Watching
  • 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.
  • slimhsS Offline
    slimhsS Offline
    slimhs
    wrote on last edited by slimhs
    #1

    I have a list of 32 radio buttons,I have this program:

    ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
        ui->scrollArea->verticalScrollBar()->setSingleStep(30);
        for(int i=0;i<32;i++){
    
    
                    radio_name.clear();
                    radio_name.append("RadioButton_");
                    radio_name.append(QString::number(i+1));
    
                    radioButtons[i]=new QRadioButton(ui->scrollAreaWidgetContents);
                    radioButtons[i]->setObjectName(QString::fromUtf8(radio_name.toStdString().c_str()));
                   radioButtons[i]->setProperty("DeviceIndex", i +1);
    }
    ui->scrollAreaWidgetContents->setGeometry(0,0,480,960);
    
         QList<QRadioButton *> allPButtons = this->findChildren<QRadioButton *>();
    
         foreach (QRadioButton *button, allPButtons)
         {
             keyboardMapper->setMapping(button, button);
    
             connect(button, SIGNAL(clicked(bool)), keyboardMapper, SLOT(map()));
         }
    
    

    the problem is on the instruction

     keyboardMapper->setMapping(button, button);
    

    How can I fix it??

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      @slimhs Instead of mapping you can use this new signal-slot connection.

      connect(radioButton, &QRadioButton::clicked, [=](bool checked){
         qDebug() << button << checked; //the exact button with state 
      });
      

      You can add this in for loop where you create new RadioButtons.
      Note that this requires c++11 compliant compiler.

      157

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        where do you construct keyboardMapper?

        also, for what you are trying to do there is QObject::sender which is bad programming but it works

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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