Results 1 to 4 of 4

Thread: QTcpSocket connected signal problem

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTcpSocket connected signal problem

    I have a QTcpSocket that connects to a server.

    I instantiate the tcpSocket, and connectToHost.

    Everything is fine, then the "connected" signal should be emitted, but it is not.

    Qt Code:
    1. tcpSocket->connectToHost(QHostAddress("localhost"), quint16(35310));
    2. connect(tcpSocket, SIGNAL(connected()), this, SLOT(connectedToServer()));
    3. connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(read()));
    4. connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
    To copy to clipboard, switch view to plain text mode 

    What is wrong ?
    Why the "connected" signal is emitted when I close the window ?
    Last edited by probine; 22nd December 2006 at 13:56. Reason: wrong spell

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket connected signal problem

    We'd have to see more code to be able to answer that... Maybe you're blocking the flow somewhere?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTcpSocket connected signal problem

    Sure, might not be the case in this one, but it is generally a good idea to create the signal-slot connection first and invoke the method emitting signals afterwards..

    In this case the connectToHost() is not blocking, and the socket actually starts connecting as soon as it's invoked. If the connection is fast enough, you can easily miss a state change or two (during the beginning of the connection).
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket connected signal problem

    But why then does he get the "connected" signal later when he closes the dialog? Of course your remark is true, but I doubt that's the thing causing trouble in this particular situation.

Similar Threads

  1. Problem with QTcpSocket and QDataStream
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 16th September 2006, 13:08
  2. Replies: 16
    Last Post: 7th March 2006, 15:57
  3. QTcpSocket disconnection problem
    By erdi in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2006, 21:50

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.