Results 1 to 2 of 2

Thread: communication between objects and tcpsockets

  1. #1
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt3
    Platforms
    MacOS X

    Default communication between objects and tcpsockets

    Can someone tell me a good solution how to communicate between client objects? In this case :how can i send a message from a single class of the client object to other Client objects with a message?
    Its a server application and here is the code:
    Qt Code:
    1. Server::Server(QObject *parent) :
    2. QTcpServer(parent)
    3. {
    4.  
    5. !this->listen(QHostAddress::Any,2234))
    6.  
    7. this->threadpool = new QThreadPool(this);
    8. threadpool->setMaxThreadCount(10);
    9. threadpool->setExpiryTimeout(30000);
    10.  
    11. }
    12.  
    13. Server::~Server(){
    14.  
    15. this->close();
    16.  
    17. }
    18.  
    19. void Server::incomingConnection(int handle){
    20.  
    21. Client * client = new Client();
    22. klient->setAutoDelete(false);
    23.  
    24. client->setSocketDescriptor(handle);
    25. this->threadpool->tryStart(client);
    26.  
    27.  
    28. }
    29.  
    30. Client class:
    31.  
    32. void Client::run(){
    33. connect(this,SIGNAL(readyRead()),this,SLOT(readData()));
    34.  
    35.  
    36. }
    37.  
    38.  
    39. void Client::readData(){
    40.  
    41. //reading and sending forward to all objects of this class
    42.  
    43. }
    To copy to clipboard, switch view to plain text mode 

    Is it possible and a good solution to create a static member QList<Client*> and iterate inside the
    readyread funcion to gaina all objects of that class and post an event? SOmething like that:

    Qt Code:
    1. void Client::readData(){
    2.  
    3. Client * tmp = iterating QList<Client*>
    4. {
    5. QCoreApplication::postEvent(tmp,NewMyEvent(message));
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 


    }

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: communication between objects and tcpsockets

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. form and its objects communication
    By eva2002 in forum Qt Programming
    Replies: 9
    Last Post: 31st January 2010, 01:49
  2. Replies: 3
    Last Post: 9th January 2010, 15:47
  3. Example of SSL communication
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2009, 23:41
  4. Replies: 7
    Last Post: 18th July 2006, 21:33
  5. Communication Help Pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 25th May 2006, 13:22

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.