donglebob
21st October 2008, 09:57
Hi,
I have a Producer-Thread which collects data all the time. This data is from low level, it cant understand the logic.
For this reason the producer thread sends the data to the correct Consumer-Thread.
(data-type0 to consumer0 etc...)
The consumer threads are created by the producer-thread dynamically.
I thought that sending the data from producer to consumer with signals/slots would be good for this situation. (so I need dynamic signal connections???)
After sending data to consumerN is finished producer has to resume its work, collecting other data.
The consumerN, which received the data, recognizes that data has arrived.
(SLOT was called by the signal connection).
The consumerN should now start to work on the received data to understand the logic behind it.
While consumerN is working on that data, producer should be able to collect other data.
The new data could be send to another conumer or the same conumerN again.
Meanwhile the user can change something on the GUI.
These changes must be emitted to the consumers. Every consumer has an own Tab (tab widget) with other elements on it .
I know that the other way, changing something on the GUI from the consumer-thread (non-gui-thread) ,is not possible.
The data, which die consumer get and understands should be printed in the GUI.
It can be a kind of Plot or some other changes.
Any Idea how I can do that?
But my main problem is following:
I want that my consumer-threads live as long as I want.
They should not die after working on one piece of data.
They should work on it and when finished they should wait (for example a wait condition).
And they should be able to receive Signals.
That means I need the call to exec() in my run() and I need an own loop where I work on my received data and after working wait with a wait-condition.
I dont know how to realize that. Need some help!
Something like that:
consumer:
void run() {
while(some_flag){
if(data_has_arrived) // flag ist set by my SLOT (producer sent a signal)
do_sth_with_data(); //work on data
WAIT_CONDITION_GOES_HERE // i think I should use it....
}
exec() // i must call this to receive signals
}
Here I can loop in my while(some_flag) or I can go to exec()
When I reach exec() i cannot go back to work on data, which will come later.
- I dont' want that the consumer Thread dies.
- It must be able to wait for signals ( for example new work)
- it must work on new received data, after working it must wait for new work
How can I do that?
I think User hb had a similar problem here ?!??!?!
http://www.qtcentre.org/forum/f-qt-programming-2/t-processevents-for-a-qthread-9195.html
but I couldn't really understand the sollution.
I have a Producer-Thread which collects data all the time. This data is from low level, it cant understand the logic.
For this reason the producer thread sends the data to the correct Consumer-Thread.
(data-type0 to consumer0 etc...)
The consumer threads are created by the producer-thread dynamically.
I thought that sending the data from producer to consumer with signals/slots would be good for this situation. (so I need dynamic signal connections???)
After sending data to consumerN is finished producer has to resume its work, collecting other data.
The consumerN, which received the data, recognizes that data has arrived.
(SLOT was called by the signal connection).
The consumerN should now start to work on the received data to understand the logic behind it.
While consumerN is working on that data, producer should be able to collect other data.
The new data could be send to another conumer or the same conumerN again.
Meanwhile the user can change something on the GUI.
These changes must be emitted to the consumers. Every consumer has an own Tab (tab widget) with other elements on it .
I know that the other way, changing something on the GUI from the consumer-thread (non-gui-thread) ,is not possible.
The data, which die consumer get and understands should be printed in the GUI.
It can be a kind of Plot or some other changes.
Any Idea how I can do that?
But my main problem is following:
I want that my consumer-threads live as long as I want.
They should not die after working on one piece of data.
They should work on it and when finished they should wait (for example a wait condition).
And they should be able to receive Signals.
That means I need the call to exec() in my run() and I need an own loop where I work on my received data and after working wait with a wait-condition.
I dont know how to realize that. Need some help!
Something like that:
consumer:
void run() {
while(some_flag){
if(data_has_arrived) // flag ist set by my SLOT (producer sent a signal)
do_sth_with_data(); //work on data
WAIT_CONDITION_GOES_HERE // i think I should use it....
}
exec() // i must call this to receive signals
}
Here I can loop in my while(some_flag) or I can go to exec()
When I reach exec() i cannot go back to work on data, which will come later.
- I dont' want that the consumer Thread dies.
- It must be able to wait for signals ( for example new work)
- it must work on new received data, after working it must wait for new work
How can I do that?
I think User hb had a similar problem here ?!??!?!
http://www.qtcentre.org/forum/f-qt-programming-2/t-processevents-for-a-qthread-9195.html
but I couldn't really understand the sollution.