【发布时间】:2016-10-31 23:32:25
【问题描述】:
我正在尝试创建一个弹出窗口,该弹出窗口将 (1) 是非模态的,(2) 携带稍后将在用户单击 ok 事件时处理的上下文数据。到目前为止,我有下面的代码,它确实作为非模态弹出。我知道msgBox->open(this, SLOT(msgBoxClosed(QAbstractButton *)) 和msgBoxClosed(QAbstractButton *button) 可以工作,但是当我将QStringList collisionSections 添加到SLOT 参数时。我收到此错误:
QObject::connect: No such slot MainWindow::msgBoxClosed(QAbstractButton *, collisionSections) in src\mainwindow.cpp:272
QObject::connect: (receiver name: 'MainWindow')
我理解,因为它在那里声明了 SLOT,但我不知道如何去做我想做的事情,即将 QString 作为内容传递给我的信号,并让它与 buttonClicked() 事件很好地配合qmessagebox 在 OK 点击时抛出。我也可能以错误的方式处理这个问题,如果是这样,请告诉我。非常感谢任何帮助!
void MainWindow::do_showCollisionEvt(QStringList collisionSections)
{
QString info = "Resolve sections";
for (QString section : collisionSections)
{
if (!section.isEmpty())
{
info.append(" [" + section + "] ");
qDebug() << "Emitting node off for:" << section;
emit nodeOff(section);
}
}
QMessageBox *msgBox = new QMessageBox;
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText("Collision event detected!");
msgBox->setInformativeText(info);
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->setModal(false);
msgBox->open(this, SLOT(msgBoxClosed(QAbstractButton *, collisionSections)));
}
void MainWindow::msgBoxClosed(QAbstractButton *button, QStringList collisionSections) {
QMessageBox *msgBox = (QMessageBox *)sender();
QMessageBox::StandardButton btn = msgBox->standardButton(button);
if (btn == QMessageBox::Ok)
{
for (QString section : collisionSections)
{
if (!section.isEmpty())
{
qDebug() << "Emitting nodeON for:" << section;
emit nodeOn(section);
}
}
}
else
{
throw "unknown button";
}
}
【问题讨论】: