Results 1 to 3 of 3

Thread: after closing modal window, display is updated in the wrong order

  1. #1
    Join Date
    Dec 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default after closing modal window, display is updated in the wrong order

    cross posting from [URL="https://stackoverflow.com/questions/47740565"]stackoverflow:

    The following C++/Qt code is used to launch a modal dialog that prompts for a file selection:

    Qt Code:
    1. QFileDialog dlg(parent, caption, dir, filter);
    2. dlg.setOption(QFileDialog::DontUseNativeDialog);
    3. dlg.setViewMode(QFileDialog::Detail);
    4. dlg.setAcceptMode(QFileDialog::AcceptOpen);
    5. dlg.setReadOnly(true);
    6. dlg.setProxyModel(new OpenFileProxyModel);
    7. dlg.setFileMode(FileDialog::ExistingFiles);
    8. if (dlg.exec())
    9. return dlg.selectedFiles();
    To copy to clipboard, switch view to plain text mode 
    This is correctly executed. Then, however, the calling application proceeds to load the selected files, and updates a file list in the main window - before the modal dialog is properly closed. This results in a badly disfigured transient display. Part of the QFileDialog remain visible, while others are overwritten by updated parts of the main window.

    How to prevent this behavior?

    Other discussion threads suggest

    qApp->processEvents();

    which, however, has no effect here.
    Last edited by high_flyer; 11th December 2017 at 11:15. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: after closing modal window, display is updated in the wrong order

    however, the calling application proceeds to load the selected files, and updates a file list in the main window - before the modal dialog is properly closed.
    How do you know that this is what is happening - how do you know that the modal dialog is not "properly closed" - and even if ?
    The very notion is very strange to me.
    I believe something else is the problem, but without more code its hard to say.

    To test you claim you could have the application load the selected files etc in a slot connected to the file dialog's destroyed signal.
    If then it still behaved like that, then you know your theory was wrong.
    If it works well, then you were right, and you have your solution - but that will surprise me, and would indicate a Qt bug.

    Are you overriding the paintEvent() of your main window?
    It looks more like something of this sort.

    Try calling update() in your main window right after the file dialog closes see if this helps.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: after closing modal window, display is updated in the wrong order

    I have had dialogs "hang" (i.e. not disappear after closing) when the application does some heavy processing with the result returned by the dialog. If the dialog is invoked by a slot, and the slot goes on to do other things before returning to the event loop, the dialog can stay posted until that processing is done and the event loop resumes. Perhaps this is what you are seeing.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Modal dialog only modal to base window?
    By SvenA in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2015, 09:25
  2. Replies: 1
    Last Post: 26th November 2014, 05:50
  3. wrong order of elements in QList
    By qtbeginner0 in forum Qt Programming
    Replies: 25
    Last Post: 22nd November 2013, 18:08
  4. Replies: 4
    Last Post: 2nd December 2011, 01:39
  5. QTextStream input and output executing in wrong order
    By jrmrjnck in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2010, 16:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.