How to wait for another window to close in QT C++?

138 Views Asked by At

I have a window. When I press a button, it executes a function. That function at some point might start another window. In that window the user can do things. While that window is open, I do not the other window to be used.

So here is what I tried to achieve this:

try {
 this->hide();
 vector<ICD11> postcoordinations = dbhandler->QueryHasPostcoords(temp,ICD11cluster);
 if(!postcoordinations.empty()){
  ClusterPostcoordination *cp = new 
  ClusterPostcoordination(nullptr,&temp,&postcoordinations,&ICD11cluster);
  cp->show();
  QEventLoop loop;
  cp->connect(cp, SIGNAL(destroyed()),  &loop, SLOT(quit));
  loop.exec();
  }
 this->show();
}  catch (exception &e) {
 qDebug() << e.what();
}

I am using a QEventLoop that does its thing while the 2nd window is open. Once I close the other window, the 1st window pops up for a split second, and closes once it finished the current function. I'd expect it to finish the current function, then keep displaying the window, so other things can be done with it. The try-catch block does not catch anything. What could be the problem, how can I fix it? Or is there a better way for me to make the main thread wait for the other window to finish before continuing?

0

There are 0 best solutions below