c++ - Application crashes when opening a window qt -
i create programme shows question answers user. application uses 3 forms: main menu, login menu , game form, , inherit abstract class called form; because allows utilize of mill method, create new window when signal gofw emitted actual form.
the "loop" shows windows following: mainmenu -> loginmenu -> gameform -> mainmenu... problem when game finished (e.g. count of remaining questions zero) gameform emits signal gofw application crashes after show() method (i see white window no buttons before crash). debugger show messagebox error:
the inferior stopped because triggered exception. stopped in thread 0 by: exception @ 0x723f7b93, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance).
and qtcreator opens file called: disassembler(qhash::findnode)
this code of mill method:
void formfactory::init(int formtype) { ///if formtype == 1 mainmenu showed if(formtype == main_menu_type) { //inizializza il puntatore actualform = new mainmenu(); } ///else if == 2 show profilemenu else if(formtype == profile_menu_type) { actualform = new loginmenu(); } ///else if == 3 show gameform else if(formtype == game_form_type) { actualform = new gameform(); } ///else if there no match launch exception else throw unexpectedidex(); connect(actualform, signal(gofw(int)), this, slot(displayform(int))); } void formfactory::displayform(int i) { reset(); init(i); ///show form pointed actualform actualform->show(); } void formfactory::reset() { disconnect(actualform, signal(gofw(int)), this, slot(displayform(int))); ///if actualform pointing form, delete , set actualform 0 if(actualform!=0) delete actualform; actualform = 0; }
and code of mainmenu.cpp is
mainmenu::mainmenu() { setupgui(); } void mainmenu::setupgui() { playbutton = new qpushbutton(tr("play")); infobutton = new qpushbutton(tr("info")); quitbutton = new qpushbutton(tr("exit")); ///connect clicked signal related slot connect(infobutton, signal(clicked()), this, slot(info())); connect(quitbutton, signal(clicked()), this, slot(quit())); connect(playbutton, signal(clicked()), this, slot(emitsig())); ///create vertical layout qvboxlayout *layout = new qvboxlayout; layout->addwidget(playbutton); layout->addwidget(infobutton); layout->addwidget(quitbutton); setlayout(layout); setwindowtitle(tr("menu principale")); } void mainmenu::emitsig() { emit gofw(2); }
thank help, luca
i'd suggest rethink solution, seems overcomplicated mill method. utilize 3 variables forms, "new" operation 1 time each, , utilize show() / hide() methods depending on signals.
to reply crash problem, 1 reason see because "delete" in slot. qt doc:
warning: deleting qobject while pending events waiting delivered can cause crash. must not delete qobject straight if exists in different thread 1 executing. utilize deletelater() instead, cause event loop delete object after pending events have been delivered it.
c++ forms qt layout window
No comments:
Post a Comment