如何在c ++中的QButtonGroup按钮上放置一个事件?

时间:2013-11-29 21:10:17

标签: c++ qt events

我的buttonGroup已加载45个按钮我想在点击按钮后做任何事情这是我的代码:

#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";
}

1 个答案:

答案 0 :(得分:0)

按钮组包含带参数QAbstractButton *或int的信号,因此您应将此信号与具有适当参数的插槽连接。

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

或者您可以将每个按钮连接到某个插槽。

您可以在此处阅读更多内容:http://harmattan-dev.nokia.com/docs/library/html/qt4/signalsandslots.html

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