QLocalSocket and QDataStream
-
I am getting data from from QLocalSocket and try to put it to QDataStream. Then, I see data stream is empty, what I do wrong?
auto socket = qobject_cast<QLocalSocket*>(sender()); QByteArray bytes = socket->readAll(); QDataStream stream(&bytes, QIODevice::ReadOnly); qDebug() << bytes; // I got here while (!stream.atEnd()) { QString receiveString; stream >> receiveString; qDebug() << receiveString; // I not got here }
-
@aliks-os Do you mean the body of your while loop is never executed?
Is bytes empty or does it contain something? -
qDebug() << receiveString;
Does not contain anything. Loop executes
-
@aliks-os are you sure the bytes in your QByteArray are String conform?
If not, then your QString may be terminated. -
yes I sure, I send a string from client
-
@aliks-os QByteArray is much more versatile than QString.
Also do you send a QString from the client side? as QString stream operator is sure to come with an overhead that needs to be present in the data
-
@aliks-os said in QLocalSocket and QDataStream:
I got
"Hello12345"That means that
bytes
is just an array of (ascii?) encoded bytes. this is not how you useQDataStream
normally.Could you show us the code for the other side of the connection? the one sending the "Hello12345"?
Post 9 of 10