QDialogButtonBox 按钮没有响应
QDialogButtonBox buttons not responding
当我运行以下函数时,对话框显示所有内容都已到位。问题是按钮无法连接。"确定"和"取消"不响应鼠标单击。
void MainWindow::initializeBOX(){
QDialog dlg;
QVBoxLayout la(&dlg);
QLineEdit ed;
la.addWidget(&ed);
//QDialogButtonBox bb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
//btnbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
la.addWidget(buttonBox);
dlg.setLayout(&la);
if(dlg.exec() == QDialog::Accepted)
{
mTabWidget->setTabText(0, ed.text());
}
}
在运行时,cmd 中的错误显示:没有像 accept() 和 reject() 这样的插槽。
您在连接中指定了错误的接收器。它是具有accept()
和reject()
插槽的对话框,而不是主窗口(即 this
)。
因此,相反,您只需要:
connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject()));
现在,当您单击按钮时,对话框将关闭,exec()
将返回QDialog::Accepted
为"确定",或"QDialog::Rejected
"表示"取消"。
相关文章:
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- QML按钮点击功能执行顺序
- 当用户超过按钮点击限制时报告
- 函数计算用户按下按钮的频率
- 热键/按钮,根据需要进行编译,但不运行(在F5和Ctrl+Shift+B之间)
- FLTK:按下哪个按钮 - 将数字传递给按钮的回调 (lambda)
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 垂直方向的 Gtk3+ 旋转按钮 (c/c++)
- Qt自定义QPush按钮未显示在布局上
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- SDL 操纵杆按钮按下/C++
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- Qt中来自不同功能的按钮引用
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- ImGui 在单击按钮后冻结
- WinAPI 无法创建按钮
- CButton派生的'SubclassDlgItem'在VS2015 CLR的CDialogBar上不可见,但响应按钮点击,在VC++ 6中工作正常
- 如何使用GTKMM添加对按钮的响应
- QDialogButtonBox 按钮没有响应