PDA

View Full Version : QString, how to delete new lines



raphaelf
25th June 2008, 08:30
Hi everybody,

i am reading some information by using QProcess::readAllStandardError() and it works fine.

I would like to delete all New lines of this String, but i dont know how to do this by using the Function QString::replace or remove :crying:

Can somebody help?

Now:


Connecting to STCHPS426...


Starting PsExec service on STCHPS426...


Connecting with PsExec service on STCHPS426...


Copying I:\WinZip 8.1.exe to STCHPS426...


Starting I:\WinZip 8.1.exe on STCHPS426...



WinZip 8.1.exe exited on STCHPS426


I want to have this:


Connecting to STCHPS426...
Starting PsExec service on STCHPS426...
Connecting with PsExec service on STCHPS426...
Copying I:\WinZip 8.1.exe to STCHPS426...
Starting I:\WinZip 8.1.exe on STCHPS426...
WinZip 8.1.exe exited on STCHPS426

lyuts
25th June 2008, 09:34
Something like this



yourString.replace(QString("\n\n"), QString("\n"));

raphaelf
25th June 2008, 09:58
Hi,

it dosent work :crying:

same result:



QString information = process->readAllStandardError();
information.replace(QString("\n\n"), QString("\n"));

lyuts
25th June 2008, 11:06
How often is readAllStandardError() called? It might be that it reads and gets "Connecting to STCHPS426..." then it is called several times but nothing is in StandardError, that's why you get newlines.

One of the possible solutions is to connect a readyReadStandardError() signal of QProcess to a slot, which will call readAllStandardError().

raphaelf
25th June 2008, 11:23
yes, im calling every 21 milisecond :)



QString information = process->readAllStandardError();
QString defaulttext1 = "PsExec v1.94 - Execute processes remotely";
QString defaulttext2 = "Copyright (C) 2001-2008 Mark Russinovich";
QString defaulttext3 = "Sysinternals - www.sysinternals.com";
information.replace(defaulttext1, "");
information.replace(defaulttext2, "");
information.replace(defaulttext3, "");
information.replace("with error code 0.", "");
information.replace(QString("\n\n\n\n\n"), QString("\n"));
ui.information_te->setText(ui.information_te->toPlainText() + information);


I dont know how to delete these new lines :crying: :crying: :crying:

lyuts
25th June 2008, 11:59
Ok, then try to do this.

1. get string from standardError
2. check, if it is not empty (with isEmpty()), then do ui.information_te->setText(ui.information_te->toPlainText() + information).

lyuts
25th June 2008, 12:05
Why do you call it every 21 milisecond?

Would not it be better if you do


connect(yourProcess, SIGNAL(readyReadStandardError()), this, SLOT(readError()));
connect(yourProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
...

void yourClass::readError()
{
// call readAllStandardError()
}

void yourClass::readOutput()
{
// call readAllStandardOutput()
}

raphaelf
25th June 2008, 12:06
Hi,

no, same result with new lines



if(!information.isEmpty())
{
ui.information_te->setText(ui.information_te->toPlainText() + information);
}

lyuts
25th June 2008, 12:13
Try the way with signals and slots as in my previous post.