[Qt-interest] Can you spot my mistake.

John McClurkin jwm at nei.nih.gov
Mon Aug 24 16:33:05 CEST 2009


william.crocker at analog.com wrote:
> 
>>
>>>> Your myapp constructor doenst take in a reference to argc
>>> That is correct.
>>
>> So why *is* QApplication's constructor defined with "int & argc", 
>> rather than just "int argc"? Isn't that just asking for trouble?
>>
> 
> As Thiago pointed out, the QApplication code will remove
> arguments form the list over which it claims
> ownership and modify the arg* accordingly.
> 
> That philosophy itself is problematic.

Well, it's not problematic for those who expect and exploit that behavior.

> My app has dozens of arguments.
> Then, one day, I added a new one whose name
> happened to conflict with one of these preexisting
> Qt arguments. (I wanted my app to run in the foreground
> instead of daemoning-off and running in the background
> so I added the argument '-foreground'.)
> Now, for the first time QApplication removed an
> argument and changed the arg* parameters accordingly.
> 
> KABOOM.

Namespace collisions have been a problem for quite awhile. The 
QApplication class reference does provide a list of argument names of 
which it claims ownership.

> 
>>> Easy to miss and of dire consequences.
>>
>> Out of interest, given it took a long time for the symptoms to surface 
>> - what were they? Others on the list (including me) may encounter the 
>> same thing one day and who knows, they may remember this thread.
>>
> 
> The symptom was a crash,
> The crash occurred when Qt created the argument list
> for a low level X11 call. The arguments were incorrect
> because argc had been stepped on.
> There were some Q_ASSERT checks splashed around,
> but not quite enough.
> 
> My fix is to lie to QApplication and tell it argc is 1.
> 
> 
> 



More information about the Qt-interest-old mailing list