[Interest] Never ending thread: blocking GUI
a1291762 at gmail.com
Wed Oct 17 01:15:28 CEST 2012
On 17/10/12 01:00, Sensei wrote:
> So, if in my main thread every time I need to search I will create a
> thread, a searcher, move the searcher to the new thread.
You should probably just keep these objects around rather than
recreating them all the time.
> Am I leaking memory?
> How can I delete these objects?
Unfortunately, it's a little more complicated to clean up threads.
Here's a suggestion.
class MyObject : public QObject
MyObject(QObject *parent = 0)
thread = new QThread;
searcher = new Searcher;
connect(this, SIGNAL(search(QStringList)), searcher,
connect(searcher, SIGNAL(searchResults(QString)), this,
searcher->deleteLater(); // schedule a delete of the object
thread->quit(); // schedule the thread for termination
thread->wait(); // this will block until the above two operations
terms << "*.txt";
void search(const QStringList &terms);
void searchResults(const QString &file)
qDebug() << "got search result" << file;
More information about the Interest