Qt 消息框不会出现
Qt Message Box Won´t appear
我最近开始使用 qt,但出现了一个我不明白的问题:
在这个特定的代码中,我只想显示一个消息框,如果单击一个按钮并选中一个单选按钮,但消息框不会出现。有人可以帮忙吗?
#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:
...
};
我最近开始使用 qt,但出现了一个我不明白的问题:
在这个特定的代码中,我只想显示一个消息框,如果单击一个按钮并选中一个单选按钮,但消息框不会出现。有人可以帮忙吗?
#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:
...
};