我有一个处于某种对话状态的ClientSocket
类,我需要要求用户输入通信密码。TcpSocket
所以我创建了一个 Dialog DG::ChallangeDialog
。在DG::ChallangeDialog
s ctor 我已经
ui->setupUi(this);
QPushButton* okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
if(okButton != 0x0){
okButton->setText("Challange");
}
QObject::connect(this, SIGNAL(accepted()), this, SLOT(acceptedSlot()));
acceptedSlot
再次发出信号challanged(QString)
void ChallangeDialog::acceptedSlot(){
QString text = ui->passBox->text();
emit challanged(text);
}
在ClientSocket
我做
case Hallo:{
if(m->message().startsWith("welcome")){
DG::ChallangeDialog* dlg = new DG::ChallangeDialog;
dlg->setModal(true);
connect(dlg, SIGNAL(challanged(QString)), this, SLOT(challanged(QString)));
dlg->exec();
/*
DG::MessagePacket* res = new DG::MessagePacket((int)Hallo);
res->setMessage("challange");
send(res);
state = Challange;
*/
}
}break;
在ClientSocket::challange
插槽中,我通过套接字发送消息挑战(文本)并存储密码。
我希望对话框隐藏在那里并且正常的套接字对话继续。并且在对话框被接受或拒绝后,主应用程序退出(它退出它不会崩溃)。为什么 ?
- 我的应用程序没有其他小部件。我就像 QCoreApplication 一样工作。但我仍然使用 QApplication 因为我有一些 GUI 需求。