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 Problem closing a QMainWindow in Qt4.2

    Environment: Qt4.2 patched to use Visual Studio 2003 integration on WindowsXP

    I have just ported some code to Qt4.2 and am having a problem closing the QMainWindow. When I immediately click the close window 'x' button after launch the application throws an unhandled exception. However, if I click some widgets in the workspace area and then click the main windows 'x' button the application closes as expected. I have tried overriding the QMainWindow::close() event handler, setting attributes such as WA_DeleteOnClose and various other things all to no avail. Has anyone else come across this problem before?

  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

    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.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    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.

  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

    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.
    The QMainWindow object would get destructed twice if it's created on the stack and has that attribute set (first when closing and secondly when going out of scope). Maybe this was the case for you? This is not the case for ian, though, because for him it's working sometimes and sometimes not.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem closing a QMainWindow in Qt4.2

    Yes you're right! I have my MainWindow on the Stack of the main function. That does explain it! Thanks. I was wondering about that, but after the problem went away I didn't bother to investigate any further.

  6. #6
    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.

  7. #7
    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

  8. #8
    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.

  9. #9
    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

  10. #10
    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).

  11. #11
    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

Similar Threads

  1. run function before closing QMainWindow
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 31st August 2006, 10:21
  2. Replies: 16
    Last Post: 7th March 2006, 16: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.