Bonjour,

A partir d'un exemple j'ai fait le code suivant avec l'implémentaion de la fonction virtuelle run() en protected :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Thread : public QThread
{
	Q_OBJECT
public:
	Thread();
 
 
protected:
	void run();
 
private:
	volatile bool stopped;
	QMutex mutexListe;
};

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Thread::Thread()
{
  stopped = false;
}
 
void Thread::run()
{
  forever {
    mutexListe.lock();
    if (!Liste.isEmpty()) {
       QString jobname(Liste.first());
       Liste.removeFirst();
       mutexListe.unlock();
       //Mon code QProcess
    }
    else {
          mutexListe.unlock();
          break;
    }
  }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <QApplication>
 #include <QtCore>
 
 #include "Thread.h"
 
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
 
  int noeuds(4);
  QStringList Liste;
  Liste << "a" << "b" << "a" << "b" << "a" << "b" << "a" << "b" << "a" << "b";
 
  for (int i(0) ; i < noeuds ; ++i)
  {
  	Thread * un_thread;
  	un_thread = new Thread;
  	un_thread->run();
  }  
 
  return 0;
 }
Cependant à la compilation j'ai l'erreur suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
Thread.h: In function `int qMain(int, char**)':
Thread.h:9: error: `virtual void Thread::run()' is protected
main.cpp:18: error: within this context
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory `L:/CPP/Qt/QThread'
mingw32-make: *** [debug] Error 2