Results 1 to 7 of 7

Thread: Use QThread with Qbytearray parameter and return...+ QTCPSocket

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Use QThread with Qbytearray parameter and return...+ QTCPSocket

    Quote Originally Posted by ruben.rodrigues View Post
    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:

    Qt Code:
    1. Suppose you have a subclassed TCPSocket that has a state flag.
    2. enum MyClientState
    3. {
    4. ClientStateIdle = 0,
    5. ClientStateLogIn = 1,
    6. ClientStateFunction2 = 2,
    7. ...
    8. }
    9.  
    10. void myClient::setFlag(MyClientState state);
    11. MyClientState myClient::flag() const;
    12.  
    13.  
    14. Function1 : logging in
    15. Use an available TCPSocket
    16. Set the flag of the socket to ClientStateLogIn
    17. Write a command with the correct username and password and then forget about it.
    18.  
    19. Function2: something else
    20. Use an available TCPSocket
    21. Set the flag of the socket to ClientStateFunction2
    22. write a command ... and forget about it.
    23.  
    24. slot readyRead
    25. Get to know the sender, as in: MyClientSocket *client = static_cast<MyClientSocket *>(sender())
    26. Or, alternatively, use a QSignalMapper
    27. Get the state of the socket
    28. If ClientStateLogIn
    29. Process the incoming data
    30. 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.
    31. if ClientStatFunction2
    32. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Use QThread with Qbytearray parameter and return...+ QTCPSocket

    Here's a real life example
    It's work in progress, so it may contain some errors in handling the data.
    Attached Files Attached Files

Similar Threads

  1. Replies: 4
    Last Post: 2nd April 2010, 10:04
  2. Replies: 4
    Last Post: 1st February 2010, 14:21
  3. QTcpSocket QDataStream QByteArray
    By Grimlock in forum Newbie
    Replies: 1
    Last Post: 14th December 2009, 22:47
  4. Problem in printing the data return /read from QTcpsocket
    By skumar434 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 19:36
  5. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2008, 17:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.