qt - QWidget not closing - leaving empty window -


i have problem qwidget derivate (newpayment). it's simple window, controls , qdialogbuttonbox . has 2 slots:

void newpayment::on_buttonbox_accepted() {     //(some action going in here)     this->close(); }   void newpayment::on_buttonbox_rejected() {     this->close(); } 

when click either ok or cancel - slot triggered expected. problem is, window does not close. contents dissappears, , empty window left (window title left).

the widget exists mdisubwindow, , created so:

void hurbudclientgui::addnewpayment(int direction, int contractorid) {     foreach(qmdisubwindow* it, this->ui.mainarea->subwindowlist()) {         if ( newpayment* np = qobject_cast<newpayment*>( it->widget() )  ) {             if (np->getcontractorid() == contractorid) {                 this->ui.mainarea->setactivesubwindow(it);                 return;             }         }     }     newpayment* np = new newpayment(direction, contractorid, this);     np->setattribute(qt::wa_deleteonclose);     this->ui.mainarea->addsubwindow(np);     np->show(); } 

the interesting part is, when either:

  • click on 'x' in tre upper right corner
  • call qmdiarea::closeactivesubwindow() main window
  • call qmdiarea::closeallsubwindows() main window

the window closed properly. have overwritten qwidget::closeevent(qcloseevent * event) class:

void newpayment::closeevent(qcloseevent * event) {     qdebug() << "[" << __function__ << "]:" << "event: " << event  << "; sender:" << sender(); } 

and shows preety same event every time - no matter how try close it:

[ newpayment::closeevent ]: event:  qcloseevent(close, 0x40bd64, type = 19) ; sender: qdialogbuttonbox(0x4dfa7a8, name = "buttonbox") // hit cancel [ newpayment::closeevent ]: event:  qcloseevent(close, 0x40b634, type = 19) ; sender: qobject(0x0) // hit 'x' in window corner [ newpayment::closeevent ]: event:  qcloseevent(close, 0x40b468, type = 19) ; sender: qobject(0x0) // hit "close active sub window" parent window [ newpayment::closeevent ]: event:  qcloseevent(close, 0x40b454, type = 19) ; sender: qobject(0x0)  // hit "close sub windows" parent window 

the best part is, when hit "cancel" (the windows cleared, stays open), , click "x" or whatever - window closed, control not pass through newpayment::closeevent (i have brakepoint there - , not fire) .

it works preety same in other windows. strange, i'm preety sure worked (+- week ago) other windows (they closed after clicking ok ant performing necessary operations) . guess end analyzyig diff svn, maybe had similar issue? have had little sleep lately, maybe missed trivial?

i appreciate help.

what expect, widget not window. output closing widget, that's not same closing window.

you need have handle window if want close it. could:

  • keep pointer returned addsubwindow()
  • create window in advance, create widget parented window, set window's widget widget, , use widget's parent() access window.

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -