Results 1 to 2 of 2

Thread: QGraphicsProxyWidget usage leads to QApplication destructor crashing

  1. #1
    Join Date
    Sep 2021
    Thanked 1 Time in 1 Post
    Qt products
    Unix/X11 Windows Android

    Question QGraphicsProxyWidget usage leads to QApplication destructor crashing

    Recently I needed to insert several buttons into QGraphicsScene and implemented it as it was described in Qt examples (I use Qt 5.15.2):
    Qt Code:
    1. QMyWidget* widget;
    2. // ...
    3. // initializing widget, adding layout, adding 3 QPushButton’s to this layout
    4. QMyGraphicsScene* scene;
    5. // initializing some my scene
    6. QGraphicsProxyWidget* proxy = scene->addWidget (widget);
    To copy to clipboard, switch view to plain text mode 
    Everything works fine, aside from a mysterious crash happening on the application exit. The crash appears on Linux and Android (not observed on Windows) deep in QApplication destructor.
    What is very interesting, the crash happens only in the case, if any of the buttons present in the QGraphicsProxyWidget, was pressed during execution. If the application is started, then closed immediately without any user interaction with the buttons, - there is no crash!

    During this problem investigation, I added full cleanup that is performed when just one my QMainWindow inheritor is closed:
    Qt Code:
    1. proxy->setWidget (nullptr);
    2. scene->removeItem (proxy);
    3. delete proxy;
    To copy to clipboard, switch view to plain text mode 
    But this doesn’t help, and when all QWidget’s and QGraphicsScene are already destroyed, the crash still happens in QApplication::~QApplication.
    Any help with this issue would be appreciated.
    Last edited by redsoft; 25th June 2022 at 18:11.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 847 Times in 834 Posts
    Qt products

    Default Re: QGraphicsProxyWidget usage leads to QApplication destructor crashing

    You haven't shown enough code to give any idea what could be wrong, but personally I think you are chasing a red herring (or barking up the wrong tree, or whatever metaphor you want for "looking in the wrong place").

    Whenever I have an unexplained crash like this that occurs in some weird place, it is usually something I have done in some totally unrelated place in the program that just happens to corrupt memory in the place where the crash occurs. For example, I recently had a crash in the QDomDocument destructor that occurred only in Release mode builds. It turned out that I was writing past the end of an array (an off-by-one error) and this caused a memory corruption that caused the crash only in Release mode. In Debug mode, the bug was still there, but the array's memory location didn't result in code corruption.

    So since you observe this error only when one of the buttons is pressed, start looking there. Start by disconnecting the button's signals from any slots you have connected to them. Problem goes away? OK, reconnect the signals and slots one by one until you see a problem again. Next, comment out all the code in each slot and try again. Eventually you will discover what is wrong.

    Look to make sure you are obeying Qt's widget ownership rules. I have had bugs where I manually deleted a QWidget / QObject that was actually owned by another widget, causing a crash at program exit.

    Make sure you are not creating multiple instances of the same widget, and saving the pointers into the same variable (thus resulting in a dangling pointer that is not accessible). Make sure that if you do create multiple instances, you call deleteLater() on the unused pointer so it gets disconnected and cleaned up properly.

    These kinds of bugs are frustrating and difficult to find, but the last thing to do is to assume it's a Qt bug. It isn't :-)
    <=== 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. Replies: 1
    Last Post: 15th September 2021, 17:32
  2. Serializing a QHash leads to SEGFault
    By gbonnema in forum Newbie
    Replies: 10
    Last Post: 7th January 2015, 18:00
  3. Replies: 0
    Last Post: 14th May 2014, 11:23
  4. Crashing without debug mode- No crashing with gdb debugger
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2011, 11:27
  5. Replies: 4
    Last Post: 1st December 2008, 11:13

Tags for this Thread


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.