Solved socket->connectToHost doesn't work in Qt 5.8
-
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?
-
Hi
This is the same pc ?
Where you have both 5.7 and 5.8 installed ? -
@mrjj Yes, it's same PC.
Use MinGW.
-
Well it could be a bug in 5.8 (regression)
I would go look in
https://bugreports.qt.io/secure/Dashboard.jspaMake sure its not something simple. Like you allowed the 5.7 exe but forgot the 5.8 one etc.
-
what does
SocketError return, whenn the connection failed?
Hopefully not -1/UnknownSocketError :)
-
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(); }
-
@MChe Try
socket->setProxy(QNetworkProxy::NoProxy);
-
@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(); }
-
@MChe You should put socket->setProxy(QNetworkProxy::NoProxy); before socket->connectToHost("mymail.local", 25);
-
It's work, super! Thx :)
-
@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. :-)