I have to admit, that I don't understand something in "How does qDebug() << message work?". Apparently, at any one time, when we call qDebug() << something; something suppose to appear in the console, isn't it? But in this piece of code it will not work in a right way:
socket->write("LIST\r\n");
while(socket->waitForReadyRead())
{
str = socket->readAll().data();
qDebug() << str;
qDebug() << str.length();
}
socket->write("LIST\r\n");
QString str;
while(socket->waitForReadyRead())
{
str = socket->readAll().data();
qDebug() << str;
qDebug() << str.length();
}
To copy to clipboard, switch view to plain text mode
I will not get the length of the string in the console. I tried to put a break-point. Yes, program will stop on that point, but once again there is no result on the screen for some reason. May be I need to include something in .pro file, besides QT += network. I don't know. Could you please explain me, what's going on behind the scene in qDebug() and why it will not show any results?
Thank you beforehand.
p.s. I consider the worst scenario, when message will be received by chunks. In this case either once the length will be shown or nothing at all.
p.p.s. I solved problem in this way:
socket->write("LIST\r\n");
while(socket->waitForReadyRead())
{
arr.insert(arr.length(), socket->readAll());
qDebug() << arr.data();
qDebug() << "Length: " << arr.length();
if(arr.endsWith(".\r\n"))
break;
}
socket->write("LIST\r\n");
QByteArray arr;
while(socket->waitForReadyRead())
{
arr.insert(arr.length(), socket->readAll());
qDebug() << arr.data();
qDebug() << "Length: " << arr.length();
if(arr.endsWith(".\r\n"))
break;
}
To copy to clipboard, switch view to plain text mode
I got the right result. But why for the QString it doesn't work? I'm a bit confused. In the world of C++
std::cout
std::cout
To copy to clipboard, switch view to plain text mode
works perfectly. And we always can grab the right result for the string length... Honestly, I don't get it, how does qt interpret length-function for the QString...
Bookmarks