-1
我不能为我的生活弄清楚为什么我的功能连接后没有被正确调用。Qt插槽功能未被调用
.h文件中
class NewCustomer : public QObject {
Q_OBJECT
public:
QWidget* newCustomer = new QWidget;
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
NewCustomer(QObject *parent);
~NewCustomer();
private slots:
void aAccepted();
};
.cpp文件
void thisfunctionworksthough() {
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.exec();
}
NewCustomer::NewCustomer(QObject *parent) : QObject(parent) {
connect(this->buttonBox, &QDialogButtonBox::accepted, this, &NewCustomer::aAccepted);
connect(buttonBox, &QDialogButtonBox::rejected, thisfunctionworksthough);
newCustomer->setMinimumSize(700, 600);
newCustomer->show();
}
void NewCustomer::aAccepted() {
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.exec();
}
自由功能的作品,但在一个定义为槽不里面的类。为什么?
一个映射到Ok按钮(接受),另一个映射到取消按钮(被拒绝)。当我按确定没有任何反应,当我按下取消时,我收到消息。 – Eejin
这段代码是否编译? – HazemGomaa
@ H.G是的,虽然我删除了包含和一些其他小部件来做一个简单的例子。 – Eejin