PDA

View Full Version : terminate a QThread from GUI



OverTheOCean
24th July 2010, 21:33
Hello guys,

I'm learning QThread with a simple application ... my thread start with a modified Run() function.

in the run(), l activate a QDialog, do some stuff and wait with exec() for the user to click on QPushbutton "Keep" or "close"


Thread_PulseMeas::Thread_PulseMeas(QObject *parent):
QThread(parent)
{
diag_RealTimePlot = new QDialog;
ui_RealTimePlot.setupUi(diag_RealTimePlot);
diag_RealTimePlot->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
connect(ui_RealTimePlot.Close, SIGNAL(clicked()), this, SLOT(Close()));
connect(ui_RealTimePlot.Add, SIGNAL(clicked()), this, SLOT(Add()));
};

void Thread_PulseMeas::run( Pulse_Meas *PulseMeas)
{
diag_RealTimePlot->show();
Pulse_measure(PulseMeas);
exec();

}

void Thread_PulseMeas::Close()
{
SetKeep(false);
diag_RealTimePlot->close();
exit();
}
void Thread_PulseMeas::Add()
{
SetKeep(true);
diag_RealTimePlot->close();
exit();
}

when l click "keep" or "close", the QDIALOG is closed but the thread is not terminated ....

am l missing something there ?

regards,

Michael

tbscope
24th July 2010, 21:38
How do you check if the thread is terminated?

wysota
24th July 2010, 21:41
You can't access GUI from threads!!!

OverTheOCean
24th July 2010, 21:42
from my main program where l started the thread with run() ... it is blocked at run()....if l replace exec() with quit() in the thread::run() ....it is okay but then l can not manage the signal Keep or Close in my thread

OverTheOCean
24th July 2010, 21:46
Wysota ...

my GUI is a just a QDIALOg l mange in the Thread ...seems to work well, eexcept to exit the thread when l use signal... l read around in this forum there is limitation on calling Signal in a thread, but it is not really clear to me !!

M.

wysota
24th July 2010, 22:04
from my main program where l started the thread with run()
Are you calling run() explicitly? Then you are not starting a thread. You should be calling start(), not run().


my GUI is a just a QDIALOg l mange in the Thread ...seems to work well, eexcept to exit the thread when l use signal...
Seems you don't have a thread at all. But if you did, your code would crash while trying to access the dialog.

OverTheOCean
26th July 2010, 02:12
hey Wysota,

well l reworked my code so the GUI is manage outside the thread and l update the GUI using Signal in the Thread...and now use Start() to activate the thread.

everything works as l want.

thanks for your help,

Michael