[Development] A new approach for Qt main()

Laszlo Agocs laszlo.agocs at qt.io
Tue Dec 13 10:42:05 CET 2016


How does this handle the cases that need code before the QGuiApplication construction? AFAICS it does not.


From: Development [mailto:development-bounces+laszlo.agocs=qt.io at qt-project.org] On Behalf Of Simon Hausmann
Sent: Tuesday, December 13, 2016 10:37 AM
To: Mathias Hasselmann <mathias at taschenorakel.de>; development at qt-project.org
Subject: Re: [Development] A new approach for Qt main()


The joke of the bikeshedding aside I for one do like the idea of exporting a QObject sub-class instead of a function. That makes it easier to extend in the future with more entry-points as slots for example.


From: Development <development-bounces+simon.hausmann=qt.io at qt-project.org<mailto:development-bounces+simon.hausmann=qt.io at qt-project.org>> on behalf of Mathias Hasselmann <mathias at taschenorakel.de<mailto:mathias at taschenorakel.de>>
Sent: Monday, December 12, 2016 7:53:50 PM
To: development at qt-project.org<mailto:development at qt-project.org>
Subject: Re: [Development] A new approach for Qt main()


Seems this turned into a nice bike shed discussion quickly, so let me
use the chance to present my preferred Qt main(). I am totally convinced
that this one should rule the Qt world:

     class BlueBikeShedApplication : public QApplication

         using QApplication::QApplication;

         int run()
             if (!parseCommandLine())
                 return EXIT_FAILURE;
             if (!initializeColorBucket())
                 return EXIT_FAILURE;


             return exec();

     int main(int argc, char *argv[])
         return BlueBikeShedApplication{argc, argv}.run();

The big advantage I see in this approach is, that you work within a
proper QObject context with fully setup QApplication early. Also this
main() is sufficiently generic to be hidden in a platform specific
macro, or static library.

Thank you for reading,
Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20161213/6ee87b10/attachment.html>

More information about the Development mailing list