[Qt-interest] 2 Main windows

Bo Thorsen bo at fioniasoftware.dk
Tue Oct 4 16:55:41 CEST 2011


This is completely from memory, so it might be a bit off:

void runMyWindowDialog() {
   MyWindow w;
   QEventLoop loop;
   loop.setEventLoop(&loop);
   w.setWindowModality(Qt::ApplicationModal);
   w.show();
   loop.exec();
}

In the close event handler of the window, you have to call exit() or 
quit() on the loop (I forget which one it is, read the docs). It would 
be a bit simpler if QWidget would finally get a closed() signal, so it 
could be connected directly to the loop slot.

You can also look at the code in QDialog::exec(). But it basically does 
this.

The idea is that you run a new event loop that only works until the 
window is closed. The method I have described here won't return before 
the window is closed.

If you don't need the synchronous call, just set the window modality on 
your window.

Bo.

Den 04-10-2011 15:28, Graham Labdon skrev:
> Hello everyone
>
> Is there a way that I can get a main window to act as a dialog?
>
> I want to be able to create and show the window and then return to the
> calling code when the window is dismissed –
>
> {
>
> MyWindow w; // MyWindow is derived from QMainWindow
>
> w.show(); // would use exec for a dialog
>
> return here when window is dismissed
>
> }
>
> Thanks
>
> Graham
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest


Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list