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. socket->connectToHost doesn't work in Qt 5.8
Forum Updated to NodeBB v4.3 + New Features

socket->connectToHost doesn't work in Qt 5.8

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 8.6k 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.
  • M Offline
    M Offline
    MChe
    wrote on last edited by
    #1

    Hello!

    Pro-file:

    QT       += core gui network
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = QTCP
    TEMPLATE = app
    DEFINES += QT_DEPRECATED_WARNINGS
    SOURCES += main.cpp\
            widget.cpp
    HEADERS  += widget.h
    FORMS    += widget.ui
    

    I have simple code:

    #include "widget.h"
    #include <QApplication>
    
    #include <QtNetwork/QTcpSocket>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QTcpSocket *socket = new QTcpSocket();
        socket->connectToHost("mymail.local", 25);
    
        if (socket->waitForConnected(5000)) {
            qDebug() << "Connected";
        } else {
            qDebug() << "Not connected";
        }
    
        return a.exec();
    }
    

    Run project in Qt 5.7 — it's work (Connected).

    Run project in Qt 5.8 — it's doesn't work (Not connected).

    OS Windows 7.

    How can I fix it?

    mrjjM 1 Reply Last reply
    0
    • M MChe

      Hello!

      Pro-file:

      QT       += core gui network
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      TARGET = QTCP
      TEMPLATE = app
      DEFINES += QT_DEPRECATED_WARNINGS
      SOURCES += main.cpp\
              widget.cpp
      HEADERS  += widget.h
      FORMS    += widget.ui
      

      I have simple code:

      #include "widget.h"
      #include <QApplication>
      
      #include <QtNetwork/QTcpSocket>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QTcpSocket *socket = new QTcpSocket();
          socket->connectToHost("mymail.local", 25);
      
          if (socket->waitForConnected(5000)) {
              qDebug() << "Connected";
          } else {
              qDebug() << "Not connected";
          }
      
          return a.exec();
      }
      

      Run project in Qt 5.7 — it's work (Connected).

      Run project in Qt 5.8 — it's doesn't work (Not connected).

      OS Windows 7.

      How can I fix it?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MChe

      Hi
      This is the same pc ?
      Where you have both 5.7 and 5.8 installed ?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        @MChe

        Hi
        This is the same pc ?
        Where you have both 5.7 and 5.8 installed ?

        M Offline
        M Offline
        MChe
        wrote on last edited by
        #3

        @mrjj Yes, it's same PC.

        Use MinGW.

        mrjjM 1 Reply Last reply
        0
        • M MChe

          @mrjj Yes, it's same PC.

          Use MinGW.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @MChe

          Well it could be a bug in 5.8 (regression)
          I would go look in
          https://bugreports.qt.io/secure/Dashboard.jspa

          Make sure its not something simple. Like you allowed the 5.7 exe but forgot the 5.8 one etc.

          1 Reply Last reply
          0
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            what does

            SocketError return, whenn the connection failed?

            Hopefully not -1/UnknownSocketError :)


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            M 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              what does

              SocketError return, whenn the connection failed?

              Hopefully not -1/UnknownSocketError :)

              M Offline
              M Offline
              MChe
              wrote on last edited by MChe
              #6

              @J.Hilk

              socket->errorString() returns 'Proxy denied connection' in Qt 5.8.

              #include "widget.h"
              #include <QApplication>
              
              #include <QtNetwork/QTcpSocket>
              
              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
              
                  QTcpSocket *socket = new QTcpSocket();
                  socket->connectToHost("mymail.local", 25);
              
                  if (socket->waitForConnected(5000)) {
                      qDebug() << "Connected";
                  } else {
                      qDebug() << "Not connected";
                      qDebug() << socket->errorString();
                  }
              
                  return a.exec();
              }
              
              jsulmJ 1 Reply Last reply
              0
              • M MChe

                @J.Hilk

                socket->errorString() returns 'Proxy denied connection' in Qt 5.8.

                #include "widget.h"
                #include <QApplication>
                
                #include <QtNetwork/QTcpSocket>
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                
                    QTcpSocket *socket = new QTcpSocket();
                    socket->connectToHost("mymail.local", 25);
                
                    if (socket->waitForConnected(5000)) {
                        qDebug() << "Connected";
                    } else {
                        qDebug() << "Not connected";
                        qDebug() << socket->errorString();
                    }
                
                    return a.exec();
                }
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @MChe Try

                socket->setProxy(QNetworkProxy::NoProxy);
                

                See http://doc.qt.io/qt-5/qabstractsocket.html#setProxy

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

                M 1 Reply Last reply
                5
                • jsulmJ jsulm

                  @MChe Try

                  socket->setProxy(QNetworkProxy::NoProxy);
                  

                  See http://doc.qt.io/qt-5/qabstractsocket.html#setProxy

                  M Offline
                  M Offline
                  MChe
                  wrote on last edited by MChe
                  #8

                  @jsulm said in socket->connectToHost doesn't work in Qt 5.8:

                  socket->setProxy(QNetworkProxy::NoProxy);

                  It's returns same result.

                  #include "widget.h"
                  #include <QApplication>
                  
                  #include <QtNetwork/QTcpSocket>
                  #include <QtNetwork/QNetworkProxy>
                  
                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                  
                      QTcpSocket *socket = new QTcpSocket();
                      socket->connectToHost("mymail.local", 25);
                      socket->setProxy(QNetworkProxy::NoProxy);
                  
                      if (socket->waitForConnected(5000)) {
                          qDebug() << "Connected";
                      } else {
                          qDebug() << "Not connected";
                          qDebug() << socket->errorString();
                      }
                  
                      return a.exec();
                  }
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • M MChe

                    @jsulm said in socket->connectToHost doesn't work in Qt 5.8:

                    socket->setProxy(QNetworkProxy::NoProxy);

                    It's returns same result.

                    #include "widget.h"
                    #include <QApplication>
                    
                    #include <QtNetwork/QTcpSocket>
                    #include <QtNetwork/QNetworkProxy>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        QTcpSocket *socket = new QTcpSocket();
                        socket->connectToHost("mymail.local", 25);
                        socket->setProxy(QNetworkProxy::NoProxy);
                    
                        if (socket->waitForConnected(5000)) {
                            qDebug() << "Connected";
                        } else {
                            qDebug() << "Not connected";
                            qDebug() << socket->errorString();
                        }
                    
                        return a.exec();
                    }
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @MChe You should put socket->setProxy(QNetworkProxy::NoProxy); before socket->connectToHost("mymail.local", 25);

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

                    M Y 2 Replies Last reply
                    6
                    • jsulmJ jsulm

                      @MChe You should put socket->setProxy(QNetworkProxy::NoProxy); before socket->connectToHost("mymail.local", 25);

                      M Offline
                      M Offline
                      MChe
                      wrote on last edited by
                      #10

                      @jsulm

                      It's work, super! Thx :)

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @MChe You should put socket->setProxy(QNetworkProxy::NoProxy); before socket->connectToHost("mymail.local", 25);

                        Y Offline
                        Y Offline
                        yundorri
                        wrote on last edited by yundorri
                        #11

                        @jsulm
                        Very Thanks!!!
                        Without setProxy(), the connectToHost() and write() seemed ok with no errorString(), but could not Tx and Rx.
                        You gave me the lights. :-)

                        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