[Interest] Never ending thread: blocking GUI
Tibold Kandrai
dom at dotzteam.com
Tue Oct 16 15:29:32 CEST 2012
Or you could use ThreadPools, depending on the task you need to accomplish:
http://doc.qt.digia.com/stable/qthreadpool.html
Tibold
On 2012-10-16 15:24, Tibold Kandrai wrote:
> Hi,
>
> If you want a QThread to handle something Q related like, events or
> Queued SLOTS, you need to start an event loop.
> This is what you need: http://qt-project.org/doc/qt-4.8/QEventLoop.html
> But I don't know why did it hang your UI because that depends on how did
> you call your SLOT.
>
> BTW a few years ago I wrote a very small library that made handling
> multiple event loops and moving QObjects between threads. If you are
> interested I can go and find it. :)
>
> Cheers,
> Tibold
>
> On 2012-10-16 15:15, Sensei wrote:
>> Hi! I am in the middle of a crisis, since I thought I understood
>> threads, but I might be wrong!
>>
>> This is quite easy: I want to start a thread that never ends.
>>
>> Once in a while, when the GUI needs it, it will "wake the thread up",
>> and run a method of my QThread subclass, in my case, a "find in files"
>> or "rename all files", or any other method.
>>
>> I thought I could simply make run() be an infinite loop, sleeping for a
>> long period (one day).
>>
>> I was wrong: I hang my GUI.
>>
>>
>> What are your recommendations? This is what I intended:
>>
>>
>> class ScanFiles : public QThread
>> {
>> public:
>>
>> ScanFiles(QObject *parent = 0) : QThread(parent) { };
>>
>> // This should run endlessly, until the parent dies
>> void run()
>> {
>> qWarning("starting scanning thread.");
>>
>> // Where does this fit?
>> exec();
>>
>> while (1)
>> {
>> qWarning("sleeping now...");
>> // Snore for one day, now 5 secs just for debugging
>> sleep(5);
>> }
>> };
>>
>> public slots:
>>
>> // Here I will place the methods that should be run by the thread
>> QString search(const QStringList &files);
>> };
>>
>>
>>
>>
>> Now, I think my question is quite easy, for someone who understands
>> QThreads... but I'm a complete newbie here :)
>>
>>
>> Thanks & Cheers!
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
--
Tibold Kandrai
CEO @ Dotz Team
More information about the Interest
mailing list