Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top