[Development] QtSingleApplication in Qt proper?
thiago.macieira at intel.com
Tue Jun 21 03:06:55 CEST 2016
On terça-feira, 21 de junho de 2016 01:17:07 PDT André Pönitz wrote:
> > I'd like to see KUniqueApplication deprecated, as it relies on some
> > undocumented and fragile QtDBus functionality (namely, connecting to
> > the bus before QCoreApplication is created).
> That's a reason that I have missed so far, but to be honest, I don't
> find it convincing.
> There's surely a way on the Qt side to overcome the "undocumented" part
> of the issue, and the "fragile ... before QCoreApplication is created"
> problem is a bit more generic than DBus-only, and, if taken seriously,
> might warrant a more generic solution than "incorporate some code to
> appease the worst offender".
It's the whole problem of delivering events before and after
QCoreApplication's lifetime. The event dispatcher checks if QCoreApplication
exists and, if not, drops all events on the floor[*]. That's required so that
the event filter can work.
I solved this for Qt 5.6 by creating QDaemonThread, which has no such
limitation and does not filter events (and advising everyone that this will be
the default for all aux threads in Qt 6). But by moving the handling of D-Bus
events to another thread, we exposed other problems in KUniqueApplication's
code that assumed that some events would be handled but not some other ones,
> What irks me more here is the inconsistent reasoning. I seem to get
> messages of "we need to use this super-duper-but-unreadable XYZ
> construct to save 42.3 bytes in code size" and "well, you know, that's
> just a few hundred lines extra, you won't notice" at the same time
Maybe, but that's not the case here.
I'm saying that a proper QtSingleApplication implementation in QtCore may be
better integrated with QCoreApplication / QGuiApplication / QApplication and
do away with fragile code that tries to control the lifetime of
[*] possibly including QEvent::DeferredDelete.
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development