
Originally Posted by
ruben.rodrigues
Calm down friend!!
I'm perfectly calm.
First of all, please notice that I have posted this in the newbie section of the forum. Second my boss is totally not an idiot as he is actually one of the most intelligent person I know and I don't want to insist in using the QThread I just asked if it was possible to send parameters and have returns in a QThread Class.
Ok.
I didn't give an answer to your question because I gave you a way for you not having to ask the question in the first place.
I don't understand how I can return to the right function, the package that the class activated by the readyRead signal receives, because differently from that simple client/server application that you've recommended, the server will send packages that must be processed by 100 different functions. I'd appreciate some help to understand that.
First, you need to explain yourself a lot better. These 100 different functions, what do they do? Does each function send a different command to the server? Or does each function do something with the received response?
As I mention there are a lot more function and they all need the tcpClass send and receive. I don't see how I can do this with the Signal readyRead but once again I am a beginner.
Like I already said, create a command queu and/or multiple clients. If you can't do anything before logging in, than implement this the correct way.
Example:
Suppose you have a subclassed TCPSocket that has a state flag.
enum MyClientState
{
ClientStateIdle = 0,
ClientStateLogIn = 1,
ClientStateFunction2 = 2,
...
}
void myClient::setFlag(MyClientState state);
MyClientState myClient::flag() const;
Function1 : logging in
Use an available TCPSocket
Set the flag of the socket to ClientStateLogIn
Write a command with the correct username and password and then forget about it.
Function2: something else
Use an available TCPSocket
Set the flag of the socket to ClientStateFunction2
write a command ... and forget about it.
slot readyRead
Get to know the sender, as in: MyClientSocket *client = static_cast<MyClientSocket *>(sender())
Get the state of the socket
If ClientStateLogIn
Process the incoming data
If multiple lines, check if you get everything (you need to provide a way to know when a response is complete like sending the size of the response too (like in http) or a control character.
if ClientStatFunction2
Process the incoming data
Suppose you have a subclassed TCPSocket that has a state flag.
enum MyClientState
{
ClientStateIdle = 0,
ClientStateLogIn = 1,
ClientStateFunction2 = 2,
...
}
void myClient::setFlag(MyClientState state);
MyClientState myClient::flag() const;
Function1 : logging in
Use an available TCPSocket
Set the flag of the socket to ClientStateLogIn
Write a command with the correct username and password and then forget about it.
Function2: something else
Use an available TCPSocket
Set the flag of the socket to ClientStateFunction2
write a command ... and forget about it.
slot readyRead
Get to know the sender, as in: MyClientSocket *client = static_cast<MyClientSocket *>(sender())
Or, alternatively, use a QSignalMapper
Get the state of the socket
If ClientStateLogIn
Process the incoming data
If multiple lines, check if you get everything (you need to provide a way to know when a response is complete like sending the size of the response too (like in http) or a control character.
if ClientStatFunction2
Process the incoming data
To copy to clipboard, switch view to plain text mode
How hard can this be?
And once again, feel free to use threads, and I think someone will answer your question about the threads.
I still think you don't need them and I give you a solution that doesn't need them.
Bookmarks