我有一个名为AlarmSetup的对话框,继承自QDialog,并且按钮排列如下:
// button box
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |ButtonBox::Help, Qt::Horizontal, this);
buttonBox->button(QDialogButtonBox::Ok)->setText("übernehmen");
buttonBox->button(QDialogButtonBox::Cancel)->setText("abbrechen");
buttonBox->button(QDialogButtonBox::Help)->setText("Hilfe");
connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(slotCancel()));
connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(slotHelp()));
在第二个对话框 AlarmWindow 中,我有一个名为 AlarmWindow::slotOpen() 的槽函数,在其中我正在创建一个新的 AlarmSetup 实例并评估 AlarmSetup::exec() 的返回代码:
void AlarmWindow::slotOpen() // we create a new instance of AlarmSetup
{
if ( DBG_ALARM ) qDebug() << "AlarmWindow::slotOpen() triggered";
int alarmId = mAlarm.getAlarmIdFromAlarmMap( objectName() );
AlarmData alarmData = mAlarm.mAlarmMap.value( alarmId );
//qDebug() << "alarmData:" << alarmData << "| alarmId:" << alarmId;
AlarmSetup* alarmSetup = new AlarmSetup( mAlarm, alarmData, alarmId );
int res = alarmSetup->exec();
qDebug() << "AlarmWindow -> AlarmSetup() returned:" << (res==QDialog::Accepted? "QDialog::Accepted":"QDialog::Rejected");
...
}
无论我在AlarmSetup中点击哪个按钮,res始终为QDialog::Rejected!对应的按钮分别是标准按钮QDialogButtonBox::Ok和QDialogButtonBox::Cancel,对应的信号分别是SIGNAL(accepted())和SIGNAL(rejected()),因此我不明白为什么返回值是错误的!
请注意,对话框AlarmSetup的工作正常。
有没有解决方案使返回值res正常工作?
感谢您的时间。
这是slotOK()的代码:
void AlarmSetup::slotOk()
{
if (DBG_ALARM) qDebug() << "AlarmSetup::slotOk() triggered";
QTime time = timeBox->time();
time.addSecs(60); // next full minute
time.setHMS( time.hour(), time.minute(), 0 );
AlarmData alarmData( alarmActiveBox->isChecked()
, QDateTime( calendar->selectedDate(), time )
, titleBox->text()
, textBox->document()->toPlainText()
, alarmSound->isChecked()
, alarmSoundBox->text()
, alarmRepeatActive->isChecked()
, numBox->text().toInt()
, unitBox->currentText()
, mFileName );
//qDebug() << "data from Setup:" << alarmData;
emit signalSetAlarm( alarmData, mAlarmId );
close();
}
slotOk
的实现是什么? - king_nak