[Interest] Two QCoreApplication objects with a twist

Konstantin Tokarev annulen at yandex.ru
Fri Nov 17 17:22:42 CET 2017



17.11.2017, 19:11, "Thiago Macieira" <thiago.macieira at intel.com>:
> On sexta-feira, 17 de novembro de 2017 00:17:29 PST Lorenz Haas wrote:
>>  you can't use two QCoreApplication instances in a single application,
>>  I know. There's also a nice warning:
>>  https://github.com/qt/qtbase/blob/5.10/src/corelib/kernel/qcoreapplication.c
>>  pp#L795. The reason, I guess, has to do with the static variables used in
>>  QCA (?).
>
> And all the other "static" variables stored in QCoreApplicationPrivate and
> derived classes.
>
>>  Now, however, please imagine the following scenario and please be
>>  assured that I am neither convinced by nor advising such an
>>  architecture:
>>
>>  - Win32 based
>>  - Main Application uses Qt5 with QApplication
>>  - Shared library linked against Qt4 (Core)
>>  - Qt5-Application uses the library
>>  - This Qt4-linked library starts an Qt4-QCoreApplication (for being
>>  able to use Signal/Slots).
>
> Signals and slots do not require QCoreApplication.

But queued connections do (or is standalone QEventLoop enough?)

>
>>  What are the technical reasons why you should also not do that, if
>>  there are? ... because static variables do not count in that scenario,
>>  at least I think so.
>
> You may need to do that if you have a plugin or a library component from a
> third party whose sources you do not control. The above situation could happen
> actually more commonly on Linux, where loading certain non-Qt libraries may
> cause in turn Qt 4 to be loaded because it was expected to be there.
>
> On Linux, the above is a recipe for disastaer. The best outcome is that it
> will quickly crash.
>
> On Windows, however, it is possible to load two libraries that have the same
> symbols, since the symbol import tables name which DLLs to import the symbols
> from. So a Qt5 DLL will not accidentally find Qt4 and vice-versa.
>
> Your problem will be the event loops. On Unix systems, I know they won't
> integrate with each other. On Windows... I don't know.
>
> I personally do not recommend the above situation, but it may work.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-- 
Regards,
Konstantin



More information about the Interest mailing list