PDA

View Full Version : Passing parameters to run() or start() method in Qthread class



mdecandia
27th March 2007, 09:18
Hi,
I need to pass parameters to the run() method of a Qthread class.
Actually I set this parameters by a class method that inizialize members in the class but i need to pass them directly to run() or start() method.

Is this possible?

Thanks,
Michele

guilugi
27th March 2007, 09:27
Well, you can't pass any parameters to the start method (except priority),
but you can use an intermediate function (something like start_with_params),
that can receive them, set your members, and finally run the thread.

wysota
27th March 2007, 12:09
How about simply:

class MyThread : public QThread {
public:
MyThread(...){
m_arg = -1;
}
void setArg(int a){ m_arg = a; }
protected:
void run(){
doSomething(m_arg);
}
private:
int m_arg;
};