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. tcp socket error signal
Qt 6.11 is out! See what's new in the release blog

tcp socket error signal

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.9k 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    Hi,

    I'm trying to handle error(QAbstractSocket::SocketError socketError) signal

        sk = new QTcpSocket(this);
    
        connect(sk, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
            [=](QAbstractSocket::SocketError err){
                    qDebug()<<"SocketError";
                });
    

    for example : In my Tcp client app if i call write() before connectToHost() QtCreator application output will say
    QIODevice::write (QTcpSocket): device not open

    but my lambda is neever called,; please tell me what i'm doing wrong

    kshegunovK 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      You are doing nothing wrong. That's just a qWarning() debug message, not an error reported by the socket

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • ODБOïO ODБOï

        Hi,

        I'm trying to handle error(QAbstractSocket::SocketError socketError) signal

            sk = new QTcpSocket(this);
        
            connect(sk, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
                [=](QAbstractSocket::SocketError err){
                        qDebug()<<"SocketError";
                    });
        

        for example : In my Tcp client app if i call write() before connectToHost() QtCreator application output will say
        QIODevice::write (QTcpSocket): device not open

        but my lambda is neever called,; please tell me what i'm doing wrong

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        Treat warnings you get from Qt as user-code errors. To that end, writing to a socket that's not opened is definitely a dubious choice. Write to the socket after it's valid, if you need, check with QTcpSocket::isValid before you commit to writing.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        4
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          Thank you for inputs

          @kshegunov said in tcp socket error signal:

          To that end, writing to a socket that's not opened is definitely a dubious choice.

          i try to trigger a socket error so QAbstractSocket::error signal is emitted and i can check if my handler is called.

          kshegunovK 1 Reply Last reply
          0
          • ODБOïO ODБOï

            Thank you for inputs

            @kshegunov said in tcp socket error signal:

            To that end, writing to a socket that's not opened is definitely a dubious choice.

            i try to trigger a socket error so QAbstractSocket::error signal is emitted and i can check if my handler is called.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @LeLev said in tcp socket error signal:

            i try to trigger a socket error so QAbstractSocket::error signal is emitted and i can check if my handler is called.

            This is not a socket error, @VRonin said it; it can't be as you have no socket (yet). This is a programming error deal with it accordingly. Think of it as if you were to trip an assert somewhere.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2

            • Login

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