boss_bhat
26th July 2006, 11:11
Hi all,
I am new to Threads!! I have a class derived from QWidget and it runs a thread
which prints out messages. I use start, sleep, resume and terminate button to
controle the thread. I dont know how to controle `sleep and resume` of thread.
Here is the piece of code I have written,
ThreadWidget::ThreadWidget(QWidget *parent )
:QWidget(parent)
{
thinThread = new ThinThread();
QPushButton *startButton= new QPushButton("start",this);
QPushButton *sleepButton= new QPushButton("sleep",this);
QPushButton *resumeButton= new QPushButton("resume",this);
QPushButton *terminateButton = new QPushButton("terminate",this);
connect (startButton,SIGNAL (clicked()), thinThread, SLOT(start()));
connect (terminateButton,SIGNAL (clicked()), thinThread, SLOT(terminate()));
//connect (resumeButton,SIGNAL (clicked()), ??;
//connect (sleepButton,SIGNAL (clicked()), ??;
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(startButton);
mainLayout->addWidget(sleepButton);
mainLayout->addWidget(resumeButton);
mainLayout->addWidget(terminateButton);
setLayout(mainLayout);
}
//ThinThread is derived from QThread!!
void ThinThread ::run ()
{
while(1)
{
sleep(1);
cout <<" in the thread\n";
}
}
Can some body explain how to do it?
Thanks in advance,
Boss
I am new to Threads!! I have a class derived from QWidget and it runs a thread
which prints out messages. I use start, sleep, resume and terminate button to
controle the thread. I dont know how to controle `sleep and resume` of thread.
Here is the piece of code I have written,
ThreadWidget::ThreadWidget(QWidget *parent )
:QWidget(parent)
{
thinThread = new ThinThread();
QPushButton *startButton= new QPushButton("start",this);
QPushButton *sleepButton= new QPushButton("sleep",this);
QPushButton *resumeButton= new QPushButton("resume",this);
QPushButton *terminateButton = new QPushButton("terminate",this);
connect (startButton,SIGNAL (clicked()), thinThread, SLOT(start()));
connect (terminateButton,SIGNAL (clicked()), thinThread, SLOT(terminate()));
//connect (resumeButton,SIGNAL (clicked()), ??;
//connect (sleepButton,SIGNAL (clicked()), ??;
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(startButton);
mainLayout->addWidget(sleepButton);
mainLayout->addWidget(resumeButton);
mainLayout->addWidget(terminateButton);
setLayout(mainLayout);
}
//ThinThread is derived from QThread!!
void ThinThread ::run ()
{
while(1)
{
sleep(1);
cout <<" in the thread\n";
}
}
Can some body explain how to do it?
Thanks in advance,
Boss