Neel Basu
Neel Basu

Reputation: 12904

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 ?

Upvotes: 2

Views: 967

Answers (1)

Caleb Huitt - cjhuitt
Caleb Huitt - cjhuitt

Reputation: 14941

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.

Upvotes: 2

Related Questions