PDA

View Full Version : QThread blocks gui



skoegl
26th October 2007, 16:36
For learning Qt programming I'm working on a little gpl project: http://pertubis.berlios.de

you can obtain the source code via svn:



svn checkout svn://svn.berlios.de/pertubis/trunk/pertubis
or browse the code:


https://svn.berlios.de/wsvn/pertubis

It's a bit tricky compiling since you need the (unstable) trunk version of paludis installed to link with, and an up-to-date gentoo system.

Now I have encountered a problem with a QThread derived class "src/ItemInstallTask.{cc,hh}", which handles package compilation and installation. The QThread::run() method only calls a predefined function from paludis api, which is doing the dirty work. While the thread is running, the Gui is completely blocked. I don't understand why that happens. And how to solve the issue. Perhaps someone can give me a hint, what I'm doing wrong.

Stefan

jacek
26th October 2007, 16:54
How do you start that thread? Also make sure it doesn't touch the GUI.

jpn
26th October 2007, 16:54
You should call QThread::start() instead of QThread::run().

skoegl
26th October 2007, 17:11
class Install : public QThread,
public paludis::InstallTask
{
Q_OBJECT
public:
Install(QObject* pobj,
DatabaseView* main,
const paludis::DepListOptions & options,
paludis::tr1::shared_ptr<const paludis::DestinationsSet> destinations);
~Install() {}
...

};



I have to be more precise the next time, sorry. I'm using start() for starting the thread. The work is done in Install::run()->execute().
The problem is, I have to pass a lot of text to a output window like a terminal like the gcc output and a lot more gentoo specific.

jacek
26th October 2007, 21:55
The problem is, I have to pass a lot of text to a output window like a terminal like the gcc output and a lot more gentoo specific.
Accessing a widget from a non-GUI thread is a Really Bad Thing(tm). Make sure you use queued connections instead.

skoegl
27th October 2007, 14:02
@jacek:

Ok, thanks. I've switched to SIGNAL/SLOT "message passing", and checked it into svn.

@all:

I tried with and without sending message (QString) to the main thread. The gui is still blocked while the thread is running. After the job is finished, the Gui is again responsively.

How can I determine, what's the reason of this block?

jacek
29th October 2007, 12:09
How can I determine, what's the reason of this block?
Try setting a breakpoint on QThread::start() to see whether you really start the thread.