Pergunta

Eu tenho algo assim:

void ReadFileAndConvert ()
{
    QFile File (Directory + "/here/we/go");

    if(File.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream Stream (&File);
        QString Text;

        do
        {
            Text = Stream.readLine();
            Text = Text.simplified();
            // Here I want to convert the multiline QString Text into a oneline QString

// ...
}

O texto QString consiste em um texto multilinha que preciso converter em um texto/QString online.Como posso conseguir isso?saudações

Foi útil?

Solução

Coloque seu texto em um QStringList, E use QStringList::join(), por exemplo.

QStringList doc;
[...]
Text = Stream.readLine();
Text = Text.simplified();
doc << Text;
[...]
QString final = doc.join(" ");

Outras dicas

Você poderia usar o readAll função de QTextStream para obter uma string contendo todo o seu texto e então usar o replace função de QString para remover novas linhas:

QString oneLineText = Stream.readAll().replace("\n"," ").simplified();

Se você tiver um arquivo grande, é melhor usar o readLine função.

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