Results 1 to 9 of 9

Thread: QString, how to delete new lines

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Unhappy QString, how to delete new lines

    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

    Can somebody help?

    Now:
    Qt Code:
    1. Connecting to STCHPS426...
    2.  
    3.  
    4. Starting PsExec service on STCHPS426...
    5.  
    6.  
    7. Connecting with PsExec service on STCHPS426...
    8.  
    9.  
    10. Copying I:\WinZip 8.1.exe to STCHPS426...
    11.  
    12.  
    13. Starting I:\WinZip 8.1.exe on STCHPS426...
    14.  
    15.  
    16.  
    17. WinZip 8.1.exe exited on STCHPS426
    To copy to clipboard, switch view to plain text mode 

    I want to have this:
    Qt Code:
    1. Connecting to STCHPS426...
    2. Starting PsExec service on STCHPS426...
    3. Connecting with PsExec service on STCHPS426...
    4. Copying I:\WinZip 8.1.exe to STCHPS426...
    5. Starting I:\WinZip 8.1.exe on STCHPS426...
    6. WinZip 8.1.exe exited on STCHPS426
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString, how to delete new lines

    Something like this

    Qt Code:
    1. yourString.replace(QString("\n\n"), QString("\n"));
    To copy to clipboard, switch view to plain text mode 
    Last edited by lyuts; 25th June 2008 at 09:44.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QString, how to delete new lines

    Hi,

    it dosent work

    same result:

    Qt Code:
    1. QString information = process->readAllStandardError();
    2. information.replace(QString("\n\n"), QString("\n"));
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString, how to delete new lines

    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().
    Last edited by lyuts; 25th June 2008 at 11:11.
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QString, how to delete new lines

    yes, im calling every 21 milisecond

    Qt Code:
    1. QString information = process->readAllStandardError();
    2. QString defaulttext1 = "PsExec v1.94 - Execute processes remotely";
    3. QString defaulttext2 = "Copyright (C) 2001-2008 Mark Russinovich";
    4. QString defaulttext3 = "Sysinternals - www.sysinternals.com";
    5. information.replace(defaulttext1, "");
    6. information.replace(defaulttext2, "");
    7. information.replace(defaulttext3, "");
    8. information.replace("with error code 0.", "");
    9. information.replace(QString("\n\n\n\n\n"), QString("\n"));
    10. ui.information_te->setText(ui.information_te->toPlainText() + information);
    To copy to clipboard, switch view to plain text mode 

    I dont know how to delete these new lines
    Think DigitalGasoline

  6. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString, how to delete new lines

    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).
    I'm a rebel in the S.D.G.

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString, how to delete new lines

    Why do you call it every 21 milisecond?

    Would not it be better if you do
    Qt Code:
    1. connect(yourProcess, SIGNAL(readyReadStandardError()), this, SLOT(readError()));
    2. connect(yourProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
    3. ...
    4.  
    5. void yourClass::readError()
    6. {
    7. // call readAllStandardError()
    8. }
    9.  
    10. void yourClass::readOutput()
    11. {
    12. // call readAllStandardOutput()
    13. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QString, how to delete new lines

    Hi,

    no, same result with new lines

    Qt Code:
    1. if(!information.isEmpty())
    2. {
    3. ui.information_te->setText(ui.information_te->toPlainText() + information);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  9. #9
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString, how to delete new lines

    Try the way with signals and slots as in my previous post.
    I'm a rebel in the S.D.G.

Similar Threads

  1. char* to QString. Segfault after delete []
    By TheRonin in forum Qt Programming
    Replies: 9
    Last Post: 19th June 2008, 13:20
  2. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.