qtcpsocket

Qt/C++ QTcpSocket causes memory leak, not sure why

别来无恙 提交于 2019-12-10 12:17:21
问题 I am creating a simple(ish) telnet server and am now debugging with valgrind. the code runs great, but valgrind complains about memory lost when the program terminates...and the culprit is the line where I create a new QTcpSocket: void TelnetConnection::run() { tcpSocketPtr = new QTcpSocket(); // ** remove this due to parent error if (!tcpSocketPtr->setSocketDescriptor(socketDescriptor)) { emit error(tcpSocketPtr->error()); return; } } I tried passing 'this' to the QTcpSocket() but then the

QTcpSocket receiving transfer

假如想象 提交于 2019-12-08 05:59:31
问题 I'm having issues with receiving a transfer. QTcpSocket->readAll() does not read enough bytes when I'm sending to it. When I send 15k bytes, it reads only some part of it and then does nothing. What am I doing wrong? QByteArray array; array = socket->readAll(); //just reads some part, not fully. Why does this happen? 回答1: Most probably the socket didn't receive all data yet when you call readAll() . This is because of TCP communication happens in small packets (each having around 1KB of data,

How to find Version of Qt?

泄露秘密 提交于 2019-12-04 08:54:09
问题 How do I know which version of Qt I am using? When I open Qt Creator it shows "Welcome to Qt Creator 2.3". In the build setting, however, it shows Qt Version 4.7.1. 回答1: qmake-qt5 --version or qmake --version 回答2: Starting with Qt 5.3 you can use: qtdiag This prints a bunch of useful information. The first line includes the version: Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160407) on "xcb" 回答3: All the version info is in PyQt5.Qt: import inspect from

PyQt QTcpServer: How to return data to multiple clients?

泪湿孤枕 提交于 2019-12-03 10:09:12
问题 I am looking to create a QTcpServer using PyQt that can simultaneously return data to 2 or more clients. I assume that this will require threading. Using the threadedfortuneserver.py example as a test case (included with PyQt4, on my system it is found in /usr/share/doc/python-qt4-doc/examples/network), I want to connect multiple clients and each time one of the clients asks for a fortune, the other clients also get updated with a message like "Client X just received the fortune 'blah blah

PyQt QTcpServer: How to return data to multiple clients?

寵の児 提交于 2019-12-03 00:40:29
I am looking to create a QTcpServer using PyQt that can simultaneously return data to 2 or more clients. I assume that this will require threading. Using the threadedfortuneserver.py example as a test case (included with PyQt4, on my system it is found in /usr/share/doc/python-qt4-doc/examples/network), I want to connect multiple clients and each time one of the clients asks for a fortune, the other clients also get updated with a message like "Client X just received the fortune 'blah blah blah'". I understand how the fortuneserver/client program works, but it seems that the client connections

How to make sure that readyRead() signals from QTcpSocket can't be missed?

帅比萌擦擦* 提交于 2019-11-30 10:48:31
问题 When using QTcpSocket to receive data, the signal to use is readyRead() , which signals that new data is available. However, when you are in the corresponding slot implementation to read the data, no additional readyRead() will be emitted. This may make sense, as you are already in the function, where you are reading all the data that is available. Problem description However assume the following implementation of this slot: void readSocketData() { datacounter += socket->readAll().length();

How to make sure that readyRead() signals from QTcpSocket can't be missed?

老子叫甜甜 提交于 2019-11-29 21:26:10
When using QTcpSocket to receive data, the signal to use is readyRead() , which signals that new data is available. However, when you are in the corresponding slot implementation to read the data, no additional readyRead() will be emitted. This may make sense, as you are already in the function, where you are reading all the data that is available. Problem description However assume the following implementation of this slot: void readSocketData() { datacounter += socket->readAll().length(); qDebug() << datacounter; } What if some data arrives after calling readAll() but before leaving the slot

Qt, Sending multiple data types from client to server + data Streaming

谁说胖子不能爱 提交于 2019-11-29 08:49:43
I have a Client/Server based Qt application, using QTcpServer and QTcpSocket, I managed to do the connection and send some data back and forth between the client and the server. The client sends many types of data to the server (string, int, files and a real time audio stream) and since my server impliment a single data input SLOT (readyRead()): connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); I don't know how could I distinguish between all this received data and call respectively the right function in the server. Example (in the server): - if I receive string => call function

How to use QTcpSocket instance multiple times with couple second intervals?

◇◆丶佛笑我妖孽 提交于 2019-11-28 13:13:01
I have to repeat the same request with QTcpSocket multiple times with a couple seconds intervals. Easy task but I can't get it to work with only one instance of object. How to connect to server again using the same instance of QTcpSocket? I've tried reset(), resume(), flush(), open() in many diffrent combinations and it has done nothing. I'm unable to connectToHost() for second time... All you have to do is to connectToHost() , use the connection, then disconnectFromHost() . That's it. Nothing more, nothing less. The below example illustrates the reuse of both client and server socket

Error while using QTcpSocket

走远了吗. 提交于 2019-11-28 11:07:42
问题 I am creating a (very basic) MJPG server to show webcam data on a browser. I have partly managed to do it so far. Here is my code: TcpServer::TcpServer(QObject *parent) : QObject(parent) { server = new QTcpServer(this); // whenever a user connects, it will emit signal connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); if (!server->listen(QHostAddress::Any, 9999)) qDebug() << "Server could not start"; else qDebug() << "Server started!"; } ... void TcpServer::newConnection()