Results 1 to 4 of 4

Thread: QFileDialog won't close when I tell it to

  1. #1
    Join Date
    May 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QFileDialog won't close when I tell it to

    I create a QFileDialog, call getOpenFileName on it, then try to close it. After that, I open the file in my code (which takes a while). My problem is that the QFileDialog doesn't close until after my code to open the file completes. Why is this? If I try to change the cursor on the QFileDialog to the WaitCursor, it doesn't take affect until after the open operation completes.

    How do I get this QFileDialog to close right after getting a filename, or at least display the WaitCursor when the 'open' button is pressed?

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QFileDialog won't close when I tell it to

    Quote Originally Posted by Compeau View Post
    I create a QFileDialog, call getOpenFileName on it, then try to close it.
    Why do you create a QFileDialog object? QFileDialog::getOpenFileName() is a static function.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QFileDialog won't close when I tell it to

    It's because your following code blocks the GUI thread. After receiving the file call
    Qt Code:
    1. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    and your dialog will close. Also have a look at keeping the GUI responsive. It was an article in Qt Quarterly.

  4. #4
    Join Date
    May 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog won't close when I tell it to

    Quote Originally Posted by Lykurg View Post
    It's because your following code blocks the GUI thread. After receiving the file call
    Qt Code:
    1. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    and your dialog will close. Also have a look at keeping the GUI responsive. It was an article in Qt Quarterly.
    Thanks! I read the article, and used the following line of code to run my time-consuming open code asynchronously after getting the filename.

    QMetaObject::invokeMethod(this, "slot name", Qt::QueuedConnection);

    This completely fixed my problem.

Similar Threads

  1. Close button in a tab
    By mitro in forum Newbie
    Replies: 2
    Last Post: 16th May 2008, 10:22
  2. Close a QMdiSubwindow
    By John_P in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2008, 17:23
  3. when close QTextStream
    By mattia in forum Newbie
    Replies: 1
    Last Post: 24th November 2007, 13:17
  4. Close event
    By gyre in forum Newbie
    Replies: 3
    Last Post: 20th November 2007, 13:49
  5. How to close application?
    By beerkg in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2006, 19:26

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
  •  
Qt is a trademark of The Qt Company.