I learn from the following links that sub classing a QThread is not a correct way of using it...the proper way is to subclass the QObject and then move the object of QObject class to the respective thread using moveToThread() function...i followed the following links.. link 1 and link 2...but my question is then how will i be able to use msleep() and usleep() protected static functions ? or will i use QTimer to make a thread wait for some time ?
No need for timers. For waiting, Qt provides QWaitCondition. You can implement something like this:
#include <QWaitCondition>
#include <QMutex>
void threadSleep(unsigned long ms)
{
QMutex mutex;
mutex.lock();
QWaitCondition waitCond;
waitCond.wait(&mutex, ms);
mutex.unlock();
}
This is a normal function. You can of course implement it as a member function too, if you want (it can be a static
member in that case.)