[Development] A new approach for Qt main()

Mathias Hasselmann mathias at taschenorakel.de
Mon Dec 12 19:53:50 CET 2016


Hi,

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

     public:
         using QApplication::QApplication;

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

             setupBrush();

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



More information about the Development mailing list