へのパラメータの受け渡し(1)非モーダルで、(2)ユーザがokイベントをクリックしたときに後で処理されるコンテキストデータを運ぶポップアップを作成しようとしています。これまで私は非モーダルとしてポップアップする以下のコードを持っています。私はmsgBox->open(this, SLOT(msgBoxClosed(QAbstractButton *))
とmsgBoxClosed(QAbstractButton *button)
が働いていますが、QStringList collisionSections
をSLOTパラメータに追加したときは分かります。QtMessageBox信号からbuttonClickシグナルハンドラスロット
QObject::connect: No such slot MainWindow::msgBoxClosed(QAbstractButton *, collisionSections) in src\mainwindow.cpp:272
QObject::connect: (receiver name: 'MainWindow')
が、私は私の信号にコンテンツとしてのQStringに渡している私が欲しいものをやって行くと持ってする方法がわからない:私はこのエラーを取得しますqmessageboxがOKクリックでスローするbuttonClicked()イベントでうまくいきます。私はまた、これに間違った方法で接近している可能性がありますので、私に知らせてください。どんな助けでも大歓迎です!
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";
}
}
はありがとうございました!これはそれでした。私はあなたの助言に従った。私が行った変更は 'void MainWindow :: msgBoxClosed(QAbstractButton * button)'に改名されました。 –
あなたのために働いてくれてありがとうとうれしいです。私はそれについて考えましたが、コピーされたコードを編集中に欠席しました。私は答えを更新します。 –
C++ではCの代わりにC++のキャストを使用することをお勧めします。この場合、 'static_cast'、' qobject_cast'、または 'dynamic_cast'のいずれかが返されます。 –