Il 11/04/19 00:18, Jason H ha scritto:
In a QObject who is exported to QML, and is instantiated just below the 
top-level Window:
//  in the object's open() method:
if (!_serialPort.open(QIODevice::ReadWrite))
        qApp->quit(); // won't actually quit - no use if I can't use the serial 
port. (because another instance is using it)

Then I have a ready() signal that is emitted when the serial device is ready, 
however the QML, when I hook onReady, it never gets called. I have to use a 
Component.onCompleted at the top level. However, there is async serial I/O 
happening, so there is at least one event loop?

What can I do to make sure these things work?

Regarding quit(): calling it before exec() has been called yields no effects. This is documented:

https://doc.qt.io/qt-5/qcoreapplication.html#quit

If a signal connected (non-queued) to this slot is emitted before control enters the main 
event loop (such as before "int main" calls exec()), the slot has no effect and 
the application never exits

So, instead of calling quit() directly, do a queued invocation.


Regarding ready(): can't say more without looking at the code. You need to make a minimal testcase.

Anyhow, all events queued before running exec() will get dispatched when you enter the event loop. The problem with e.g. quit() is that it does not involve sending events at all, it involves setting a flag into the event loop. Flag that is never read because the event loop is not running...

HTH,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to