我最近开始使用qt,出现了一个我不理解的问题:
在这个特定的代码中,我只想显示一个MessageBox,如果点击了一个按钮并选中了一个单选按钮,但MessageBox不会出现。有人能帮忙吗?
#include "thirddialog.h"
#include "ui_thirddialog.h"
#include <QMessageBox>
ThirdDialog::ThirdDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ThirdDialog)
{
ui->setupUi(this);
this->setWindowTitle("Eingabe UWZ"); /*Titelzeile*/
}
ThirdDialog::~ThirdDialog()
{
delete ui;
}
void ThirdDialog::on_Back_clicked()
{
close();
}
void ThirdDialog::on_pushButton_clicked()
{
if(ui->radioButton->isChecked()) {
QMessageBox::information(this,"Title","1");
}
if(ui->radioButton_2->isChecked()) {
QMessageBox::information(this,"Title","2");
}
}
在我看来,您似乎需要将您的on_pushButton_clicked((与QPushButton的clicked((信号连接起来。
connect(ui->pushButton, &QPushButton::clicked, this, &ThirdDialog::on_pushButton_clicked);
要使其工作,on_pushButton_clicked((必须是一个插槽:
class ThirdDialog {
Q_OBJECT
public:
...
public slots:
void on_pushButton_clicked();
private:
...
};