[Interest] QApplication in worker thread

Ramakanth Kesireddy rama.kesi at gmail.com
Mon Aug 27 19:29:14 CEST 2018


On Thu, Aug 16, 2018 at 8:31 PM Thiago Macieira <thiago.macieira at intel.com>
wrote:

> 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.
>

    Yes we are going to migrate to the latest version of Qt 5.x in the next
few months.

>
> > 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.

GUI is run in a separate thread instead of main thread of UI app process.
 The QCoreApplication object is
  created in the same worker thread that created the first QObject. Do you
foresee any issues with the same?

>
>
> > 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.
>

  Yes found the reason for the Qt exception from qeventloop.cpp as the
eventloop is not exited before
killing the thread.
  Is there any API to wait on the eventloop till it returns zero so that
eventloop is exited normally?

>
> > 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.
> So we neednot add copy or assignment operator in private section of custom
> QWidget classes?
> --
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180827/a7d80b63/attachment.html>


More information about the Interest mailing list