[Interest] Never ending thread: blocking GUI

Sensei senseiwa at gmail.com
Tue Oct 16 15:15:06 CEST 2012

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

     ScanFiles(QObject *parent = 0) : QThread(parent) { };

     // This should run endlessly, until the parent dies
     void run()
         qWarning("starting scanning thread.");

         // Where does this fit?

         while (1)
             qWarning("sleeping now...");
             // Snore for one day, now 5 secs just for debugging

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!

More information about the Interest mailing list