[Qt-creator] Help debugging a heap error
André Pönitz
apoenitz at t-online.de
Thu Jun 5 20:56:17 CEST 2014
On Thu, Jun 05, 2014 at 02:00:08PM +0000, Murphy, Sean wrote:
> > Double deletion of a QAction(-derived) object. How are your QActions
> > created (Stack/Heap)? Do you use any other life-time management (Smart
> > pointers?) besides assigning a QObject parent?
>
> I did a search of QAction in the current project and all of my QAction
> objects are declared like so: QAction* myAction = new QAction("blag",
> this); I'm not using any smart pointers, and I don't have any QAction
> objects on the stack.
That sounds good.
> I did get rid of the segfault by removing: serPort->deleteLater(); from
> my MainWindow destructor.
Ok, that's expected, as this avoids the second deletion.
> "serPort" is a QSerialPort object that I created in the MainWindow
> constructor with no parent, then created a QThread object (which also
> apparently had no parent? This seems wrong?), and then moved the serial
> port object to that thread. I think maybe I need to parent the QThread
> object, but I don't know if this is what was causing the problem or not.
> The code, as I originally had it (with the deleteLater() call) had been
> working for months, so I'm not sure what I did to change this. As far as
> I know, I've only recently been making GUI changes, that shouldn't have
> anything to do with the thread.
Is your code accessible somewhere?
> But I think my real question right now is, how can I use QtCreator's
> debugging setup to help track this down? Currently I'm setting a
> breakpoint at MainWindow::~MainWindow, then I step through my MainWindow
> destructor, all of my code works, it's only as I exit my destructor and
> all the Qt child deletion stuff happens that it segfaults. I'm building
> my stuff in debug mode, and Dependency Walker claims the debug executable
> is looking for all the Qt debug libraries (Qt*d.dll), but I don't seem to
> be able to step into Qt code to know which QAction is causing the
> problem.
What's easiest/quickest depends a bit on your exact setup.
If your application can be compiled on Linux, then the quickest would
be to run it under valgrind, either from the command line or within
Creator by using Analyze->Valgrind Analyzer. The result would directly
point you to both deallocations (something like "Invalid free
at <address2> file2.cpp:123, address is inside a free'd block at
<address1> file1.cpp:456")
Otherwise, you could try to set a breakpoint on the QAction::~QAction()
destructor. If that works (might not, depending on you Qt build), repeated
<F5> gives you one the destruction of one QAction per iteration, if the
application is not overly big, spotting a duplicate "manually" might be
possible.
Andre'
More information about the Qt-creator
mailing list