[Interest] promoting a QGuiApplication to a QApplication?

Konstantin Tokarev annulen at yandex.ru
Wed Jul 11 16:20:51 CEST 2018



11.07.2018, 12:29, "René J.V. Bertin" <rjvbertin at gmail.com>:
> Hi,
>
> I'm tinkering with using a Qt plugin that expects a QApplication in a QGuiApplication (specifically, a QML application using QGuiApplication).
> I'm not doing anything that causes a straight crash (or haven't run into that one fatal instruction yet), but I do wonder:
>
> is it in any way possible to promote a QGuiApplication instance to a QApplication? Somewhat unexpectedly, `dynamic_cast<QApplication*>(qApp)` behaves as `static_cast` or `const_cast` in this case (= it returns qApp). Or it returns a nullptr in
>
> QGuiApplication app(argc, argv);
> QApplication *gapp = dynamic_cast<QApplication*>(&app);
>
> which is probably what you'd expect.
>
> Still, with QApplication inheriting QGuiApplication one could think that the former does some initialisation the latter lacks and that it should be possible to perform those steps at a later stade. Is it?

If application object is created as QGuiApplication, you obviously cannot cast it to QApplication.

If you want to do something only when application object is created as QApplication (or its subclass), use qApp pointer


-- 
Regards,
Konstantin




More information about the Interest mailing list