PDA

View Full Version : Creating a dynamic QML component from a non Qt thread



Valerian
5th July 2015, 05:04
Hi All,

My application has a qml view. I'm creating a dynamic component for a messagebox developed in QML using QQmlComponent.

I have a non-Qt class which needs to create this dynamic component on the the qml view.

However, I get this error that can't create this component on the main thread.

Kindly suggest how can I create this component on a non-qt thread to display on the qt thread.

anda_skoa
5th July 2015, 11:38
The other thread needs to send a signal or event to the main thread which then creates the component.

Cheers,
_

Valerian
5th July 2015, 13:13
Thanks anda_skoa for the suggestion...

Since it's not a qt class emitting signals is ruled out.. Could you explain how do i pass an event to the main thread to create this component?

Kindly advice

anda_skoa
5th July 2015, 13:30
You can either user QMetaObject::invokeMethod with Qt::QueuedConnection to invoke a lot on an object in the main thread or use QCoreApplication::postEvent() to send a custom event to an object in the main thread.

Cheers,
_