[Interest] QCoreApplication, argc parameter type

Sze Howe Koh szehowe.koh at gmail.com
Fri Jan 8 02:22:35 CET 2021


On Fri, 8 Jan 2021 at 07:39, Bernhard Lindner
<private at bernhard-lindner.de> wrote:
>
> Hi!
>
> Can someone tell me why QCoreApplication uses an 'int &argc' type parameter instead of a
> plain 'int argc'? Does QCoreApplication expect the value to change? Does it change the
> value by itself?
>
> When deriving from QCoreApplication this can cause funny crashes if one forgets to use a
> reference type in the derived class' constructor parameter. So I guess there must be a
> very good reason why QCoreApplication uses a reference instead of copy-by-value.

According to the documentation
(https://doc.qt.io/qt-5/qapplication.html#QApplication and
https://doc.qt.io/qt-5/qcoreapplication.html#QCoreApplication ):

* Note: argc and argv might be changed as Qt removes command line
arguments that it recognizes.
* Warning: The data referred to by argc and argv must stay valid for
the entire lifetime of the QCoreApplication object.


> --
> Best Regards,
> Bernhard Lindner

Regards,
Sze-Howe


More information about the Interest mailing list