Look at following code n pls let me know whether my Worker class is thread safe or not. I have a Worker class cpp as follows: m_str is Qstring member variable in Worker class n m_thread is QThread in same class.

Qt Code:
  1. Worker::Worker() {
  2. m_thread = new QThread;
  3. moveToThread(m_thread);
  4.  
  5. connect(m_thread, SIGNAL(started()), this, SLOT(process()));
  6. connect(m_thread, SIGNAL(finished()), this, SLOT(quit()));
  7.  
  8. connect(m_thread, SIGNAL(finished()), m_thread, SLOT(deleteLater()));
  9. }
  10.  
  11. Worker::~Worker() {
  12.  
  13. }
  14.  
  15. void Worker::doStart()
  16. {
  17. .... // not touching m_str
  18. m_thread->start(); // this always last stmt. in this function
  19. }
  20.  
  21. void Worker::process() {
  22. m_str = QString("Hello!");
  23.  
  24. m_thread->quit();
  25. }
To copy to clipboard, switch view to plain text mode 

and in main.cpp file

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication app(argc, argv);
  4.  
  5. Worker* worker = new Worker();
  6.  
  7. worker->doStart();
  8.  
  9. worker->thread()->wait();
  10.  
  11. worker->deleteLater();
  12.  
  13. return app.exec();
  14. }
To copy to clipboard, switch view to plain text mode