Questions tagged [qabstractsocket]

The QAbstractSocket class provides the base functionality common to all socket types.

The QAbstractSocket class provides the base functionality common to all socket types.

QAbstractSocket is the base class for QTcpSocket and QUdpSocket and contains all common functionality of these two classes. If you need a socket, you have two options:

  • Instantiate QTcpSocket or QUdpSocket.
  • Create a native socket descriptor, instantiate QAbstractSocket, and call setSocketDescriptor() to wrap the native socket.

TCP (Transmission Control Protocol) is a reliable, stream-oriented, connection-oriented transport protocol. UDP (User Datagram Protocol) is an unreliable, datagram-oriented, connectionless protocol. In practice, this means that TCP is better suited for continuous transmission of data, whereas the more lightweight UDP can be used when reliability isn't important.

QAbstractSocket's API unifies most of the differences between the two protocols. For example, although UDP is connectionless, connectToHost() establishes a virtual connection for UDP sockets, enabling you to use QAbstractSocket in more or less the same way regardless of the underlying protocol. Internally, QAbstractSocket remembers the address and port passed to connectToHost(), and functions like read() and write() use these values.

Reference: http://qt-project.org/doc/qt-5/QAbstractSocket.html

9 questions
12
votes
4 answers

Get the ping from a remote target with Qt (Windows/Linux)

Currently I use this code for retrieving the ping of a target system. However it works so far only under linux and it is likely dependent on the locale settings. To add support for windows will be likely even more complicated. Is there an easy…
dgrat
  • 2,214
  • 4
  • 24
  • 46
2
votes
2 answers

Does QIODevice::waitForReadyRead implicitly flush the output queue (waitForBytesWritten)?

If I want to write data to a remote side and wait for its answer, I need at least a waitForReadyRead. But before calling that, do I need to manually flush the output queue using waitForBytesWritten, or does Qt automatically flush the write queue for…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
1
vote
1 answer

Get SO_RCVBUF socket option value from Qt

I want to get the value of the SO_RCVBUF socket option used by Qt to be sure that it uses by default the system value (that I changed). But the following piece of code returns an "Invalid" QVariant: QUdpSocket socket; qDebug() <<…
Alexandre D.
  • 711
  • 1
  • 9
  • 28
0
votes
0 answers

Why is QOverload used to connect a signal and a slot?

I saw an example for running a TCP Server with Qt. In this example a class named Client was created, its constructor had 5 connections between signals and slots of QTcpSocket and Client class. In one of the connections this code was…
0
votes
0 answers

QT connectToHost() wrong host state

I am using QTcpSocket to connect to given host: QHostAddress oAddr( u32Addr); QTcpSocket* poSocket = new QTcpSocket(this); connect(poSocket, SIGNAL(connected()), this, SLOT(readCheckConnection())); poSocket->connectToHost( oAddr, 80); I am not…
hus
  • 117
  • 1
  • 7
0
votes
0 answers

Email not sending when using SMTP server on Qt 4

I've been making a desktop app using Qt 4 and C++. This is my code: maiwindow.cpp #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { …
Chayma
  • 3
  • 4
0
votes
0 answers

QAbstractSocket::UnsupportedSocketOperationError with QSslSocket

QAbstractSocket throws UnsupportedSocketOperationError when connecting to a host over QSslSocket::connectToHostEncrypted(), Environnement: Qt 5.9.3 Ubuntu 16.04 (virtual machine) also Qt 5.9.3 Fedora 26 (native) _socket = new…
tbone
  • 23
  • 6
0
votes
1 answer

QTcpSocket connecting results in UnknownSocketError with errorString "UnknownError"

Problem I am unable to get any further information regarding this error: QAbstractSocket::UnknownSocketError The QT QAbstractSocket::SocketError provides only a basic explanation that some error has occurred An unidentified error occurred. enum…
CybeX
  • 2,060
  • 3
  • 48
  • 115
0
votes
0 answers

QAbstractSocket::UnknownSocketError provides errorString of "UnknownError"

I am unable to get any further information regarding this error: QAbstractSocket::UnknownSocketError The QT QAbstractSocket::SocketError provides only a basic explaination that some error has occured An unidentified error occurred. enum value =…
CybeX
  • 2,060
  • 3
  • 48
  • 115