[Interest] QApplication in worker thread

Thiago Macieira thiago.macieira at intel.com
Thu Aug 16 17:01:20 CEST 2018


On Wednesday, 15 August 2018 21:33:43 PDT Ramakanth Kesireddy wrote:
> Hi,
> 
> Am using Qt 4.8.x on embedded Linux.

I'm ignoring that. The following answer applies to one of the supported 
versions of Qt right now. Any differences to the unsupported version you're 
using are your problem.

> Though it is recommended to run QApplication or GUI in main thread, could
> you please let me know if there are any limitations to create QApplication
> in worker thread?

It's not recommended. It's required. The QCoreApplication object must be 
created in the same thread as the thread that created the first QObject. 
Usually. QCoreApplication is the first QObject anyway.

Inside Qt, that thread is understood as "the main thread" or "the GUI thread". 
But it need not be the same thread that main() was run on. Just make sure that 
no other QObject was created before.

> I see below two issues as QApplication is created in worker thread but not
> sure if this is the primary reason:-
> 
> I) The exceptions being thrown from slot or elsewhere couldn't be caught
> even after implementing QApplication::Notify()?

Don't try to catch them there. That recommendation is erroneous. Instead, 
catch them before allowing your code to return to Qt.

> 2) If we add copy or assignment operator in private section of custom
> QWidget classes, signal and slot doesn't works. This shouldn't impact but
> not quite sure.

QWidgets are not copyable.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Interest mailing list