Hello everybody,
I have read the documentation concerning these topics several times, but I still have doubts on how to solve my situation. In my appication, there will be several objects each running in its own thread, each providing different functionality and each using slots a signals for communication with the others.
My first goal is to have a class (e.g. TCPSocketWrapper) which provides signal sigMessageReceived(QByteArray) or slots sendMessage(QByteArray) or slotReceveMessage(). This class just wraps the QTCPSocket - sends/receives messages through/from it a emits signal if new message is received.
Then I want to have another object in different thread, which accepts users requests, converts them to QByteArray and uses TCPSocketWrapper to send them out (e.g. Terminal). This object can also print out new messages to the user if the appropriate signal (e.g. sigMessageReceived(QByteArray)) from TCPSocketWrapper is emitted.
My idea on how to solve this situation using Qt Console Application is:
- TCPSocketWrapper and QTCPSocket should be created in QThread object in its run method
- signals and slots will not be used between TCPSocketWrapper and QTCPSocket
- Terminal can be created in the main function
- both TCPSocketWrapper and Terminal have to have their signals and slots connected somehow and somewhere.
- I should use Qt::QueuedConnection
My actual problem is located in the fourth point - where and how to connect their signals and slots?
- Should I create signals and slots in QThread object and then connect part of them with Terminal signals and slots and part of them with TCPSocketWrapper signals and slots? (QThread object as a signal proxy, which is from my point of view very complicated)
- Should I create method in QThread object which returns pointer to TCPSocketWrapper object and connect its signals and slots directly with Terminal signals and slots?
- Should I do it differently?
Thank you
Boris.
This post has been edited 2 times, last edit by "juchuchuu" (May 18th 2012, 7:48pm)