Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TcpSocket stateChanged signal is not emit
Qt 6.11 is out! See what's new in the release blog

TcpSocket stateChanged signal is not emit

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 986 Views
  • 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
    w.tkm
    wrote on last edited by w.tkm
    #1

    Hi.

    I use Tcp in an application. (No special features.)
    That application is the client, and another application is the server.

    I ran the application before running the server application.
    Then client application's socket was not emit [stateChanged].
    However, It was able to connect to the server and send/receive data.

    If the server is up and running, [stateChanged] is emit.
    Why is this?

    jsulmJ 1 Reply Last reply
    0
    • W w.tkm

      Hi.

      I use Tcp in an application. (No special features.)
      That application is the client, and another application is the server.

      I ran the application before running the server application.
      Then client application's socket was not emit [stateChanged].
      However, It was able to connect to the server and send/receive data.

      If the server is up and running, [stateChanged] is emit.
      Why is this?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @w-tkm I don't understand: if the server is not running how can your client connect and send/receive data?!

      Also, what daes this mean: "I ran the application before running the server application.( after running the server application )"? Do you start client before or after server? Please explain clearly.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply
      0
      • jsulmJ jsulm

        @w-tkm I don't understand: if the server is not running how can your client connect and send/receive data?!

        Also, what daes this mean: "I ran the application before running the server application.( after running the server application )"? Do you start client before or after server? Please explain clearly.

        W Offline
        W Offline
        w.tkm
        wrote on last edited by
        #3

        @jsulm sorry I didn't explain myself better. I start client before server.

        jsulmJ 1 Reply Last reply
        0
        • W w.tkm

          @jsulm sorry I didn't explain myself better. I start client before server.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @w-tkm Can you show your code?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          W 1 Reply Last reply
          0
          • jsulmJ jsulm

            @w-tkm Can you show your code?

            W Offline
            W Offline
            w.tkm
            wrote on last edited by w.tkm
            #5

            @jsulm

            void CcuTcp::fnTcpClientSet(QString sTcpConnectIP, quint16 uiTcpConnectPort, QString sTcpBindIP)
            {
            
                connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(fnTcpRecvData()));
                connect(m_pTcpSocket, &QAbstractSocket::stateChanged, this, &CcuTcp::fnTcpStateChanged );
            
                m_pTcpSocket->setProxy(QNetworkProxy::NoProxy);
                m_pTcpSocket->bind( QHostAddress( sTcpBindIP ), QAbstractSocket::DefaultForPlatform);
                m_pTcpSocket->connectToHost( sTcpConnectIP, uiTcpConnectPort );
            }
            
            void CcuTcp::fnTcpStateChanged()
            {
                switch ( m_pTcpSocket->state() ) {
                case QAbstractSocket::UnconnectedState:	emit fnSocketState(TCP_STATE_UNCONNECT);	break;
                case QAbstractSocket::ConnectingState:	emit fnSocketState(TCP_STATE_CONNECTING);	break;
                case QAbstractSocket::ConnectedState:	emit fnSocketState(TCP_STATE_CONNECTED);	break;
                case QAbstractSocket::ClosingState:		emit fnSocketState(TCP_STATE_CLOSING);		break;
                default: break;
                }
            }
            

            [TCP_STATE_...] is Macro.

            jsulmJ 1 Reply Last reply
            0
            • W w.tkm

              @jsulm

              void CcuTcp::fnTcpClientSet(QString sTcpConnectIP, quint16 uiTcpConnectPort, QString sTcpBindIP)
              {
              
                  connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(fnTcpRecvData()));
                  connect(m_pTcpSocket, &QAbstractSocket::stateChanged, this, &CcuTcp::fnTcpStateChanged );
              
                  m_pTcpSocket->setProxy(QNetworkProxy::NoProxy);
                  m_pTcpSocket->bind( QHostAddress( sTcpBindIP ), QAbstractSocket::DefaultForPlatform);
                  m_pTcpSocket->connectToHost( sTcpConnectIP, uiTcpConnectPort );
              }
              
              void CcuTcp::fnTcpStateChanged()
              {
                  switch ( m_pTcpSocket->state() ) {
                  case QAbstractSocket::UnconnectedState:	emit fnSocketState(TCP_STATE_UNCONNECT);	break;
                  case QAbstractSocket::ConnectingState:	emit fnSocketState(TCP_STATE_CONNECTING);	break;
                  case QAbstractSocket::ConnectedState:	emit fnSocketState(TCP_STATE_CONNECTED);	break;
                  case QAbstractSocket::ClosingState:		emit fnSocketState(TCP_STATE_CLOSING);		break;
                  default: break;
                  }
              }
              

              [TCP_STATE_...] is Macro.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @w-tkm said in TcpSocket stateChanged signal is not emit:

              case QAbstractSocket::UnconnectedState: emit fnSocketState(TCP_STATE_UNCONNECT); break;
              case QAbstractSocket::ConnectingState: emit fnSocketState(TCP_STATE_CONNECTING); break;
              case QAbstractSocket::ConnectedState: emit fnSocketState(TCP_STATE_CONNECTED); break;
              case QAbstractSocket::ClosingState:

              There are more states which you do not cover

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              W 1 Reply Last reply
              0
              • jsulmJ jsulm

                @w-tkm said in TcpSocket stateChanged signal is not emit:

                case QAbstractSocket::UnconnectedState: emit fnSocketState(TCP_STATE_UNCONNECT); break;
                case QAbstractSocket::ConnectingState: emit fnSocketState(TCP_STATE_CONNECTING); break;
                case QAbstractSocket::ConnectedState: emit fnSocketState(TCP_STATE_CONNECTED); break;
                case QAbstractSocket::ClosingState:

                There are more states which you do not cover

                W Offline
                W Offline
                w.tkm
                wrote on last edited by
                #7

                @jsulm Its status is not described because it is not particularly necessary.
                I try

                qDebug() << m_pTcpSocket->state().
                

                in fnTcpStateChanged().but, console don't show debug string

                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