[Qt-interest] Can you spot my mistake.
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Mon Aug 24 18:10:21 CEST 2009
Qt has some "internal" command line parameters ("-display", "-geometry",
"-style", etc.) that are removed by the QApplication constructor so these
parameters don't confuse the application. So after creating a QApplication
object "argc" and "argv" contain only application-specific parameters.
I don't know why it's passed by a reference instead of pointer, probably
to ensure that it's a valid variable (if it was a pointer, you could
[accidentally] pass NULL or some other invalid value).
Also I don't undestand why it might be a problem to take those pre-defined
parameters into account when naming your ones since the list of them is
known and very unlikely to change (since Qt is a toolkit used by a lot of
applications, it's very risky to add/change "internal" command line
parameters due to rather high chance of breaking something).
On Mon, 24 Aug 2009 18:53:47 +0400, Thomas Dähling
<t.daehling at googlemail.com> wrote:
> Personally I am even curious why it is not doing a simple value copy
> of argc anyway? I do not see a specific reason for passing a reference
> there.
>
> 2009/8/24, Andrew Hodgkinson <ahodgkinson at endurancetech.co.uk>:
>> On 24/08/2009 15:33, John McClurkin wrote:
>>
>>> Well, it's not problematic for those who expect and exploit that
>>> behavior.
>>
>> The use of a reference type seems to be an issue, because we have a
>> thread in which several contributors describe their encounter with the
>> same problem as the OP. I suppose this is a wider C++ consideration;
>> imagine that we used this QApplication constructor instead:
>>
>> QApplication(int * argc, char ** argv) {}
>>
>> Now we try to implement MyApp as before:
>>
>> MyApp(int argc, char ** argv) : QApplication(argc, argv) {}
>>
>> Before, the code would compile with no warnings, link, run and
>> eventually
>> crash. Now it won't even compile and the compiler's error would make the
>> mistake very obvious.
>>
>> Does anyone know why a reference rather than a pointer is seen as a
>> better choice in this particular case?
>>
>> --
>> TTFN, Andrew Hodgkinson
>> Find some electronic music at: Photos, wallpaper, software and more:
>> http://pond.org.uk/music.html http://pond.org.uk/
--
Constantin "Dinosaur" Makshin
More information about the Qt-interest-old
mailing list