Q: In Qt on Linux/X11, how do I fix main window ordering issue? I've got a Qt application that has two main windows.  On Linux, when one main window brings up a modal dialog, it comes up behind the other main window.  What can I do to cause the dialog to always come up on top of ALL main windows?
NOTE: This only happens on Linux.  We build this app on MacOSX as well, and the problem does not occur there.
Here's the code that brings up the dialog.  The stuff in the #if is all the things I've tried to bring the window forward.  I've tried various combinations and orders of these things.
    QMessageBox dialog;
    dialog.setIcon( QMessageBox::Information );
    dialog.setWindowTitle( _documentName );
    dialog.setText( tr("This document has unsaved changes. Do you want to save before closing?") );
    dialog.setInformativeText( tr("Your changes will be lost if you don't save them.") );
    dialog.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
    dialog.setDefaultButton( QMessageBox::Save );
    dialog.setFixedSize( dialog.size() );   // non-resizable window
#if STUFF_I_TRIED
    dialog.show();
    dialog.setVisible(true);
    dialog.open();
    dialog.activateWindow();
    dialog.raise();
#endif
int result = dialog.exec();

I realize that exec() should be all I need to show the window.  My idea in calling show() or open() was just to allow activateWindow() or raise() to take affect.  Just foolin' around trying to get that damn dialog to come forward.
TIA for any help!

A: All the sequcence between #if 1_ and #endif looks pretty weird to me.
Normally, to show modal dialog, only exec() is needed:
QMessageBox msgBox;
msgBox.setText("They killed Kenny, again.");
int ret = msgBox.exec();

Reference.

A: You are doing quite a bit of things between your #if 1, that is likely confusing X11.
You need only ONE of those. Since you are working with Mac and X11, I suspect you want to use open() and get a sheet.
IIRC, show() vs. open() causes different window flags to be set, so
calling them right after each other may get the window into a strange
state. Also calling show() or open() should always activate or raise the window if it is a dialog, which QMessageBox is.
Try only using one of these and seeing what happens.
