brott
7th March 2010, 14:43
Hello all,
this is my first post in this forum, so please forgive me if there is something strange or against your rules.
(You might also recognize that I am not a native speaker).
I'm trying to learn Qt and practiced some tutorials. My first target is to build a serial-bus communication. For that I studied the Classes 'QextSerialPort' and 'qserialdevice' and decided finaly to try my luck with the 'QextSerialPort' in the 'one-class'-configuration. Finaly I want to communicate this program with my microcontrollers. (in the first step similarly like a terminal).
In order to do this, I wanted to use a seperate thread to listen if there are any kind of data comming in. I had to leran, that it es useful to understand first how threads are working.
Therefore I programmed a little Widget with a second Thread. Now my problems:
When I start the thread from my widget, it starts successfully and works pretty fine. But I don't know how do quit this thread. In the Qt documentation the methods 'quit()' and 'exit(0)' are mentioned. But when I test this, the thread works on.
A second Problem is that I need to communicate with the Widget where my QextSerialPort-Class is implemented. Unfortunately a communication between Widgets and Threads is impossible (Qt Help). So what is the best way to do it? Does it make sense to do the whole Serial-Communication in the thread or is there a different and better way to work with a thread?
btw.: Qt 4.5 , linux (ubuntu 9.10), Qt Creator.
This is the code of my little test-thread:
void MyThread::run()
{
qDebug() << "In Thread";
exec();
}
void MyThread::testslot()
{
qDebug()<<"testslot opend";
}
void MyThread::killslot()
{
qDebug()<<"Kill thread";
exit(0);
}
Thanks for your Help
(if there is more code necessary, please let me know)
this is my first post in this forum, so please forgive me if there is something strange or against your rules.
(You might also recognize that I am not a native speaker).
I'm trying to learn Qt and practiced some tutorials. My first target is to build a serial-bus communication. For that I studied the Classes 'QextSerialPort' and 'qserialdevice' and decided finaly to try my luck with the 'QextSerialPort' in the 'one-class'-configuration. Finaly I want to communicate this program with my microcontrollers. (in the first step similarly like a terminal).
In order to do this, I wanted to use a seperate thread to listen if there are any kind of data comming in. I had to leran, that it es useful to understand first how threads are working.
Therefore I programmed a little Widget with a second Thread. Now my problems:
When I start the thread from my widget, it starts successfully and works pretty fine. But I don't know how do quit this thread. In the Qt documentation the methods 'quit()' and 'exit(0)' are mentioned. But when I test this, the thread works on.
A second Problem is that I need to communicate with the Widget where my QextSerialPort-Class is implemented. Unfortunately a communication between Widgets and Threads is impossible (Qt Help). So what is the best way to do it? Does it make sense to do the whole Serial-Communication in the thread or is there a different and better way to work with a thread?
btw.: Qt 4.5 , linux (ubuntu 9.10), Qt Creator.
This is the code of my little test-thread:
void MyThread::run()
{
qDebug() << "In Thread";
exec();
}
void MyThread::testslot()
{
qDebug()<<"testslot opend";
}
void MyThread::killslot()
{
qDebug()<<"Kill thread";
exit(0);
}
Thanks for your Help
(if there is more code necessary, please let me know)