I need criticism about how I use the thread class. I have the following files:
#ifndef SOME_THREAD_H #define SOME_THREAD_H #include <QObject> #include <QtCore> class Some_Thread : public QThread { Q_OBJECT public: explicit Some_Thread(QObject *parent = 0) { qDebug() << "Create some thread..."; } void run() { unsigned int count = 0; while(count < 4) { qDebug() << "Thread is doing something..." << count++; this->msleep(500); } } signals: public slots: }; #endif // SOME_THREAD_H I launch a flow so:
#include <QCoreApplication> #include <some_thread.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Some_Thread *sThread = new Some_Thread(0); QObject::connect( sThread, SIGNAL( finished() ), sThread, SLOT( deleteLater() ) ); sThread->start(); return a.exec(); } Questions to you, more experienced colleagues, are as follows:
- How to quickly clear the memory after exiting the while loop (count <4)?
- Is memory really cleared?
- Should the sThread pointer after the deleteLater () execute point to NULL?
- How do I reuse this stream?