PDA

View Full Version : how to change msleep seconds in QThread



sdastagirmca
21st July 2010, 09:48
hi All,

i want to change my msleep seconds by QSlider.According to the value change in slider ,the seconds should be changed.






class MyThread :public QThread

{

Q_OBJECT

private:

bool m_bToSuspend;

QWaitCondition m_waitCondt;

public :

QMutex mutex;

QWaitCondition wcCondition;

int count,iSeconds;

MyThread()

{

count=0;

m_bToSuspend=false;


iSeconds=1000;

}

void run()

{

QMutex waitMutex;

//qDebug()<<"count : "<<count;

for (int i=0;i<count;)

{

msleep(iSeconds);

qDebug()<<iSeconds;

emit changeValue(i);

// pause the simulator

if (m_bToSuspend)

{

waitMutex.lock();

m_waitCondt.wait(&waitMutex);

waitMutex.unlock();

}

i+=3;

}

}

signals:

void changeValue(int i);

public slots:

void getCount (int pCount)

{

count=pCount;

}

void suspend();

void startThread();

void getTimer(int pval)

{

iSeconds=pval*100;

}

};


In this getTimer() slot is used by the slider control.
connect(slider,SIGNAL(valuchanged(int)),thread,SLO T(getTimer()));
The thread is started after creating a instance of the class MyThread;

Ginsengelf
21st July 2010, 10:58
Hi, it should be


connect(slider,SIGNAL(valueChanged(int)),thread,SL OT(getTimer(int)));
note the int in getTimer.

Ginsengelf

sdastagirmca
21st July 2010, 12:27
hi Ginsengelf,

iSeconds value is not updating in run event loop.While the thread is running i want to change the msleep seconds.