Qt: confundido en la elección de QDialog en main

I have the following Qt code:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    ChoosingDialog cdlg;

    if(!startWin.exec())
    {
        // nothing chosen
        return 0;
    }

    if(cdlg.firstWindowSelected)
    {
        CFirstWindow win;
        win.show();

        return app.exec();
    }
    else
    {
        CSecondWindow win;
        win.show();

        return app.exec();
    }

}

this seems to work but it's giving me an error on "event dispatcher cleanup" in some asm line. I tried to trick a bit and I saw that the problem is related to the app.exec() calling.

Update: if I add these lines to the ChoosingDialog (this is a simple blank class auto-generated by Qt Creator)

void ChoosingDialog ::closeEvent(QCloseEvent *)
{
    exit(1);
}

I receive no errors

preguntado el 31 de julio de 12 a las 12:07

I tried your code (with a fake ChoosingDialog, CFistWindow and CSecondWindow) and except that startWin debiera ser cdlg I did not encounter any error. Can you provide the implementation of your widgets? -

I haven't widgets, I have a QDialog class with nothing on it (default generated by Qt Creator) and two QMainWindows (but the error happens also if I don't build their objects) -

Yes, startWin should be cdlg. The code seems fine. -

@Johnny: Can you post the exact error? -

llamar exit() does not sound like a proper solution. Something else is going on here. I'd suggest to track down the error (especially since its only a small piece of code) than to write a 'workaround'. -

1 Respuestas

Turns out I was using the "singleapplication" class before the QApplication.. and something went wrong on the shared memory lock.

As soon as I restarted my system the exception disappeared... bof.. do you believe in magic?

Respondido 31 Jul 12, 18:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.