Quote Originally Posted by GuiHanoi View Post
- redefinition of methods run() of Object inheriting of QThread class => Wrong way

- definition of a Worker and worker->moveToThread (QThread*) => Right way ??? (https://forum.qt.io/topic/14378/my-t...y-use-qthreads)
Both options are OK, it depends on what the thread does.
The first is the better option for something that is a single, long operation, the second is a good option for things that need events while processing.

Quote Originally Posted by GuiHanoi View Post
I developed a small project with these two methods to compare them. threadA which displays "A" and threadB which displays "B". To start/stop each threads, there are buttons. Both of these methods work (displaying AAAAA when AButton pushed, BBBBBBB when BButton pushed and ABABABABABA when both are pushed...
I personally would chose option 1 for that, way easier IMHO.

Quote Originally Posted by GuiHanoi View Post
but when I add these two connections, I have : Violation of Ox0FFFFFFFF emplacement Mutex....
Qt Code:
  1. connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
  2. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
To copy to clipboard, switch view to plain text mode 
At which of the two connects to you get the error?
It looks fine.

Quote Originally Posted by GuiHanoi View Post
Other question, in my code when i'm displaying threadID, it always displays 00000000159 (for example), for both threads ! I think I'm missing something.... Thread must NOT have the same ID ???? principles ??? (same problem in the two methods)
Your worker code does not output any thread ID, you only ever write the main thread's ID in the dialog code.

Quote Originally Posted by GuiHanoi View Post
Worker.cpp
Qt Code:
  1. Worker::Worker() { stopped = false;} // attribute of Worker instance
  2.  
  3. void Worker::process()
  4. {
  5. while (!stopped)
  6. std::cout << messageStr.toStdString(); // attribute of Worker instance
  7. emit finished();
  8. }
  9.  
  10. void Worker::stop() { stopped = true;}
  11. void Worker::start() {stopped = false;}
To copy to clipboard, switch view to plain text mode 
Concurrent access to members by multiple threads needs to be serialized, e.g. by using a mutex.
Here that is the access to "stopped", which is accessed by the worker thread in process() and by the main thread in stop() and start().

Quote Originally Posted by GuiHanoi View Post
Qt Code:
  1. void ThreadDialog::closeEvent(QCloseEvent *event)
  2. {
  3. workerA->stop();
  4. workerB->stop();
  5. threadA->wait();
  6. threadB->wait();
  7. threadA->exit();
  8. threadB->exit();
  9.  
  10. event->accept();
  11. }
To copy to clipboard, switch view to plain text mode 
QThread::exit() doesn't make much sense here. When wait() returns the thread has already exited.

Cheers,
_