Results 1 to 3 of 3

Thread: connected() signal is lost on QTcpSocket

  1. #1
    Join Date
    Apr 2014
    Posts
    53
    Thanks
    9

    Default connected() signal is lost on QTcpSocket

    Hi,

    I am using QTcpSocket object to create a socket and after that I use it to connect to a server. The problem I have is that the second time I connect to the server, I do not receive the "connected()" signal. The signal never comes. In my application every time I send something form the client to the server I disconnect. The work around I did quickly is to create the socket object again every time I need to connect, but this is obviously not good. So my question is this:

    If a QTcpSocket was already used (have been connected and discconected already) do I have to connect the "connected()" signal again on it or does it permanently works from the first time??
    I mean, do I have to execute this code:
    Qt Code:
    1. connect(sock, SIGNAL(connected()), this, SLOT(client_connected()));
    To copy to clipboard, switch view to plain text mode 
    every time I disconnect , so next time I connect it will be triggered again ?

    TIA
    Nulik

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: connected() signal is lost on QTcpSocket

    Is your QTcpSocket destroyed after you disconnect? I believe any connected signals will be removed when the destructor is called.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connected() signal is lost on QTcpSocket

    Quote Originally Posted by nuliknol View Post
    If a QTcpSocket was already used (have been connected and discconected already) do I have to connect the "connected()" signal again on it or does it permanently works from the first time??
    signal/slot connections are permanent as long as both objects exist.
    They can be explicitly disconnected and are automatically disconnected if either object is deleted.

    Cheers,
    _

Similar Threads

  1. QTcpSocket 'connected()' signal issue
    By Vladimir_ in forum Newbie
    Replies: 3
    Last Post: 24th September 2014, 21:16
  2. Replies: 7
    Last Post: 12th September 2011, 10:52
  3. Replies: 8
    Last Post: 7th June 2011, 11:39
  4. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 10:00
  5. QTcpSocket connected signal problem
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2007, 11:18

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.