[Qt-interest] Can you spot my mistake.

william.crocker at analog.com william.crocker at analog.com
Mon Aug 24 14:58:51 CEST 2009


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

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