Results 1 to 12 of 12

Thread: Problem closing a QMainWindow in Qt4.2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    Quote Originally Posted by jpn View Post
    Run the application in VS in debug mode, break it when the exception is thrown, and see the call stack (Debug->Windows->Call Stack). It should help you find the actual problem.
    I looked at this already. Here is the call stack after the exception is thrown.
    ntdll.dll!7c90eb74()
    ntdll.dll!7c90eb74()
    > QtCored4.dll!QBasicAtomic::testAndSetRelease(int expected=1, int newval=0) Line 99 + 0x18 C++
    QtCored4.dll!QMutex::unlock() Line 250 + 0xe C++
    QtCored4.dll!qt_adopted_thread_watcher_function(vo id * __formal=0x1020301f) Line 152 C++
    01fcffb4()
    ntdll.dll!7c91b298()
    kernel32.dll!7c80b683()
    ntdll.dll!7c91b298()

    Quote Originally Posted by Mike View Post
    I had the problem when using QMainWindow->setAttribute(Qt::WA_DeleteOnClose); I did remove that from my code, and now the application terminates without exception.
    My main() function creates the MainWindow on the stack and no attributes are currently being set.

    It looks like one of the custom widgets on the form doesn't seem to get shutdown properly. The mysterious thing is why it works as expected when I click the widgets on the form before closing the MainWindow but it throws the exception when I close the MainWindow immediately after launch without clicking any widgets.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem closing a QMainWindow in Qt4.2

    Are you using threads? Are you possibly modifying the GUI anyhow from an another thread than the main GUI thread?
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    Quote Originally Posted by jpn View Post
    Are you using threads? Are you possibly modifying the GUI anyhow from an another thread than the main GUI thread?
    Yes. However, the interaction between the threads is using the signal-slot mechanism.

    The thing I don't understand is why it all works as expected when I click some widgets in the form before closing the application but it throws an exception when I close the application immediately after launch.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem closing a QMainWindow in Qt4.2

    Maybe the problem is with cleaning up the thread(s)? The destructor of the QThread subclass is executed in the thread where the QThread object lives in (usually same thread where it was created in), not in the thread being executed in QThread::run().
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    Quote Originally Posted by jpn View Post
    Maybe the problem is with cleaning up the thread(s)? The destructor of the QThread subclass is executed in the thread where the QThread object lives in (usually same thread where it was created in), not in the thread being executed in QThread::run().
    This does seem to be what the problem is but I am yet to resolve it. When I click inside the form and then close the application, all threads are exiting correctly. However, when I close the applicaton immediately after launch, the application throws the error and the threads aren't exiting correctly.

    If I profile the application using DependencyWalker and close the application immediately after launch I get the following:
    Second chance exception 0xC0000008 (Invalid Handle) occurred in "c:\windows\system32\NTDLL.DLL" at address 0x7C90EB74 by thread 30.
    Thread 2 exited with code -1073741816 (0xC0000008).
    Thread 4 exited with code -1073741816 (0xC0000008).
    Thread 1 exited with code -1073741816 (0xC0000008).
    Thread 3 exited with code -1073741816 (0xC0000008).
    Thread 9 exited with code -1073741816 (0xC0000008).
    Thread 11 exited with code -1073741816 (0xC0000008).
    Thread 16 exited with code -1073741816 (0xC0000008).
    Thread 18 exited with code -1073741816 (0xC0000008).
    Thread 24 exited with code -1073741816 (0xC0000008).

    However, if I click a widget inside the form before closing, the DependencyWalker log is as follows:
    Thread 29 exited with code 0 (0x0).
    Thread 27 exited with code 0 (0x0).
    Thread 3 exited with code 0 (0x0).
    Thread 2 exited with code 0 (0x0).
    Thread 30 exited with code 0 (0x0).
    Thread 9 exited with code 0 (0x0).
    Thread 4 exited with code 0 (0x0).
    Thread 24 exited with code 0 (0x0).
    Thread 11 exited with code 0 (0x0).
    Thread 16 exited with code 0 (0x0).
    Thread 18 exited with code 0 (0x0).

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem closing a QMainWindow in Qt4.2

    When do the threads get started? How are they cleaned up? Are they running even loops?
    J-P Nurmi

  7. #7
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    This problem looks to be occurring due to a bug in Qt4.2 that occurs when using threads that are not QThreads. Here is the link to the reported bug in Task Tracker.

    http://www.trolltech.com/developer/t...ntry&id=134313

    Thanks everyone for your suggestions.

  8. The following user says thank you to ian for this useful post:

    elsbels1 (17th January 2007)

Similar Threads

  1. run function before closing QMainWindow
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 31st August 2006, 09:21
  2. Replies: 16
    Last Post: 7th March 2006, 15:57

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.