简体   繁体   中英

How can put an event on a QButtonGroup button in c++?

My buttonGroup is already load with 45 buttons i want do anything after a button is clicked this is my code:

#include "escogerpuesto.h"
#include "ui_escogerpuesto.h"
#include <iostream>

EscogerPuesto::EscogerPuesto(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::EscogerPuesto)
{
    ui->setupUi(this);
    ui->buttonGroup->connect(ui->buttonGroup, SIGNAL(clicked()), this, SLOT(asientoClickeado));
}

EscogerPuesto::~EscogerPuesto()
{
    delete ui;
}

void EscogerPuesto::asientoClickeado()
{
    std::cout<<"click en asiento";
}

Button group contains signal with parameter QAbstractButton* or int, so you should connect this signal with slot which has an appropriate parameter.

    ui->buttonGroup->connect(ui->buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
                             this, SLOT(your_slot(QAbstractButton* ));

Or you can connect each button with some slot.

You can read more here: http://harmattan-dev.nokia.com/docs/library/html/qt4/signalsandslots.html

and here http://harmattan-dev.nokia.com/docs/library/html/qt4/qbuttongroup.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM