小编gin*_*ina的帖子

如何获得哪个QradioButton调用SLOT

我创建了几个QradioButton并连接到同一个SLOT.在插槽中,我想知道哪个QradioButton调用插槽并执行相关操作.我发现使用qobject_cast和QObject :: sender()有一种方法,但它似乎不起作用.这是代码:

头文件:

class dialoginput : public QDialog
{
    Q_OBJECT

public:
    dialoginput(QWidget *parent = 0);
    QRadioButton *radio1;
    QRadioButton *radio2;
    QRadioButton *radio3;
private slots:
    void setText_2();
private:
    QLabel *label_0_0;
    QLabel *label_1;
};
Run Code Online (Sandbox Code Playgroud)

主文件:

dialoginput::dialoginput(QWidget *parent): QDialog(parent){

    label_0_0 = new QLabel("label_1:");
    label_1 = new QLabel;  

    QWidget *window = new QWidget;
    QVBoxLayout *windowLayout = new QVBoxLayout;

    QGroupBox *box = new QGroupBox("Display Type");
    radio1 = new QRadioButton("3");
    radio2 = new QRadioButton("5");
    radio3 = new QRadioButton("9");
    QVBoxLayout *radioLayout = new QVBoxLayout;

    connect(radio1,SIGNAL(clicked()),this,SLOT(setText_2()));
    connect(radio2,SIGNAL(clicked()),this,SLOT(setText_2()));
    connect(radio3,SIGNAL(clicked()),this,SLOT(setText_2())); …
Run Code Online (Sandbox Code Playgroud)

c++ qt qt4

2
推荐指数
1
解决办法
7084
查看次数

标签 统计

c++ ×1

qt ×1

qt4 ×1