0

I'm having trouble some special characters in Qt, the 2 being the quote and newline. I'm connecting to the server using telnet, and the server automatically puts quotes at the beginning and end of the input for some reason. I'm having trouble removing both the quotes and newline.

void MyClient::readyRead()
{
    if(WaitingForString())
    {
        if(socket->canReadLine())
        {
            qDebug() << "Ready to read, string expected";
            qDebug() << socket->readLine();
        }
    }
    else 
    {
        if(socket->canReadLine())
        {
            qDebug() << "Ready to read line, number expected";
            QString data = QString(socket->readLine().replace("\n", "").replace("\"", "");
            qDebug() << data;
            waitForStrings(1);
        }
    }
}

The problem with replacing the newline is described below:

My input from telnet: Hello

After the program replaces the newline: " ello (Normal output with quotes would be "Hello")

And replacing the quotes has no effect at all. I have tried also using dual backslashes since it is a RegEx, but both still have the same problems as if there were one. Help is appreciated, thanks.

Edit: This turned out to be qDebug's formatting, not a result of using Telnet or anything.

4

1 回答 1

1

您确定换行符和引号不仅是使用 qDebug() 的效果吗?

QDebug 总是在字符串周围加上引号,然后写一个换行符

于 2012-08-06T10:05:32.353 回答