[Interest] Construction of QObjects before QApplication or something else brings SEGV

Olivier BARTHELEMY barthelemy at geovariances.com
Tue Sep 17 16:51:17 CEST 2013


Ok, my valgrind warning was not related to me segmentation faults.
It was actually caused by QApplication constructor taking argc by refeence.
My class that builds the QApplication took a copy of argc as one of
its'constructor's arguments, and passed that to QApplication Constructor.
So when QApplication later referenced argc, the scope was already out of my
class constructor, so it had a reference to a deleted argc


2013/9/11 Etienne Sandré-Chardonnal <etienne.sandre at m4x.org>

> About the first problem, that's normal, since the documentation says:
> "Since the QApplication object does so much initialization, it *must* be
> created before any other objects related to the user interface are created.
> "
>
> QApplication is created in main() in most cases. Then, the GUI is created.
> Then, the main returns a->exec().
>
> Could you post the code? Otherwise, check Qt examples about how to
> initialize an application.
>
> And if you have a segfault situation, this means the behavior is likely
> undefined. So making trivial changes, changing the compiler version, eating
> a pizza, and even doing nothing may change the code's behavior.
>
> Etienne
>
>
> 2013/9/11 Olivier BARTHELEMY <barthelemy at geovariances.com>
>
>> I am having SEGFAULTS in some code just by making trivial changes that
>> should not influence the behaviour.
>> The code simply creates a QTextEdit in a QDIalog, and segfaults somewhere
>> in child calls of show() on the QDialog
>> Running valgrind, i noticed warnings about 'conditional jump or move
>> depending on uninitialized value'. Strangely, the warning has an almost
>> identical call stack than the segv.
>> The warning is apparently triggered because the class that builds the
>> QApplication and the dialog is a child of QObject, so the QObject
>> constructed before the QApplication must mess something up. Removing that
>> inheritance to QOBject, of manually creating the QApplication before
>> creating the class object removes the valgrind warning, but does not clear
>> the SEGV.
>> I have had some mixed success to remove the segv by trying multiple G++
>> versions. Older G++ versions seem to crash less (no crash in 4.1, little
>> crashes in 4.4, almost always crash in 4.6), but the results are
>> inconsistent. It seems more like the difference of generated code triggers
>> more or less the error, but what is messed up is still there.
>>
>> People there (https://code.google.com/p/eiskaltdc/issues/detail?id=601)
>> and on some other sites (google 'QWidgetPrivate::create_sys conditional
>> jump' for example) have been having similar problems of either the warning
>> or the SEGV with call stacks indicating the same problem, but without
>> solution.
>>
>> Any suggestion?
>>
>> I'm using QT4.8.5
>>
>>
>> --
>> Olivier BARTHELEMY
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>


-- 
Olivier BARTHELEMY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130917/b4c834d0/attachment.html>


More information about the Interest mailing list