Results 1 to 4 of 4

Thread: QTcpSocket 'connected()' signal issue

  1. #1
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation QTcpSocket 'connected()' signal issue

    Hello,

    I wanted to do an action when an incoming connection to the server is established from a client.

    i wrote this line :
    Qt Code:
    1. connect(socket,SIGNAL(connected()), this, SLOT(connected()));
    To copy to clipboard, switch view to plain text mode 

    while "socket" is is a pointer to QTcpSocket :
    Qt Code:
    1. socket = new QTcpSocket;
    To copy to clipboard, switch view to plain text mode 

    But the statement doesn't invoke te SLOT "connected()" .

    but when I write the following code:
    Qt Code:
    1. connect(socket,SIGNAL(disconnected()), this, SLOT(connected()));
    To copy to clipboard, switch view to plain text mode 

    The SLOT "connected()" will be called when the Client is exited.

    The issue:
    I need to invoke the SLOT when an incoming connection established from a client.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket 'connected()' signal issue

    There is some inconsistency in your posting:

    Quote Originally Posted by Vladimir_ View Post
    I wanted to do an action when an incoming connection to the server is established from a client.
    This sounds like you are writing server code.

    Quote Originally Posted by Vladimir_ View Post
    while "socket" is is a pointer to QTcpSocket :
    Qt Code:
    1. socket = new QTcpSocket;
    To copy to clipboard, switch view to plain text mode 
    while this is clearly client code.

    For a client the connect should work, i.e. the slot should be invoked when the socket establishes a connection to the server.
    For a server, the client is already connected (it has connected to the server after all), so the socket is already in "connection established" state.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket 'connected()' signal issue

    lol i was using a QTcpSocket in the server...

    So what's the SIGNAL i have to make to get the incoming connection ?? "using QTcpServer"

    thanx

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,555
    Thanks
    13
    Thanked 1,581 Times in 1,510 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTcpSocket 'connected()' signal issue

    QTcpServer... the answer is in the first few sentences of the detailed description. Try the Fortune Server Example, also linked from the detailed description section, for a complete worked example.

Similar Threads

  1. Slot connected to a generic signal
    By Momergil in forum Qt Programming
    Replies: 5
    Last Post: 28th June 2014, 23:42
  2. Replies: 11
    Last Post: 2nd February 2013, 15:39
  3. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 11:00
  4. how can i know how many slots connected to a signal?
    By yj_yulin in forum Qt Programming
    Replies: 6
    Last Post: 1st December 2008, 11:24
  5. QTcpSocket connected signal problem
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2007, 12:18

Tags for this Thread

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.