开发者

QDialog::accept quits Main Application

I have a ClientSocket Class which is a TcpSocket in a certain state of conversation I need to ask the user to enter a Communication password. So I've created a Dialog DG::ChallangeDialog . in DG::ChallangeDialogs ctor I've

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 again emits a signal challanged(QString)

void ChallangeDialog::acceptedSlot(){
    QString text = ui->passBox->text();
    emit challanged(text);
}

in ClientSocket I do

    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;

In ClientSocket::challange slot I send a Message challange (text) over the socket and store the password.


and I expect the Dialog to hide there and the normal socket conversation to continue. and after the Dialog is accepted or rejected the main application quits (It quits it doesn't crash). Why ?

  • My Application has no Other Widgets. I just works like an QCoreApplication. But still I've used QApplication cause I've some GUI Needs.


Is this the only window that is shown at this time? If so, I would guess that your QApplication instance is set to quit when the last window is closed. It is true by default.

If this is the case, you should explicitly set this to false before showing any windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜