문제

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.

도움이 되었습니까?

해결책

Are you sure, that the newline and quotes aren't only an effect of using qDebug()?

QDebug is always putting quotes around a string and writing a newline afterwards

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top