Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to connect a socket with QTcpSocket...
Forum Updated to NodeBB v4.3 + New Features

Unable to connect a socket with QTcpSocket...

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    windyweather
    wrote on last edited by
    #1

    I'm trying to make a program that connects to websites. I just want the connect to succeed or fail.
    Here is a trimmed down example that fails. The Signal slots are never called.

    It is based on this example: http://doc.qt.nokia.com/4.7/network-fortuneclient.html

    Here is my trimmed down example - source code etc.
    http://www.windyweather.net/wp/2011/01/05/qtcpsocket-unable-to-connect/

    Can you see what I am doing wrong?

    Thanks,
    Windy

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      If you switch your code to:

      @
      // connect the tcp socket to our routines
      connect( &m_tcpSocket, SIGNAL(connected()), this, SLOT(siteConnected()));
      @

      instead of

      @
      // connect the tcp socket to our routines
      connect( &m_tcpSocket, SIGNAL(readyRead()), this, SLOT(siteConnected()));
      @

      it works.

      You use readRead() if the other part of the connection is sending data to you, but that's not what you want in the example.

      If you look at the documentation for "QAbstractSocket::connectToHost":http://doc.qt.nokia.com/latest/qabstractsocket.html#connectToHost it's tsated, that the connected signal is emitted.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • W Offline
        W Offline
        windyweather
        wrote on last edited by
        #3

        Ok thanks. That would certainly explain it. I'll give that a try and get back.
        Thanks much,
        Windy

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved