Results 1 to 4 of 4

Thread: QTextEdit New line after append

  1. #1
    Join Date
    Jun 2013
    Posts
    20
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default QTextEdit New line after append

    Hey guys!

    Thats probably a very simple question but I just could not figure it out. I am using a QTextEdit as a simple Control and Command Console for an external device. When the device is sending something to the computer I display that in the QTextEdit using the append method:

    Qt Code:
    1. void DisplayText(QString msg){
    2. ui.textEdit->append(msg);
    3. }
    To copy to clipboard, switch view to plain text mode 

    As long as I am only trying to display something it is working correctly, but I want to use it as a command interface as well. So when I try to write something in the QtextEdit it is starting at the end of the last appended line, but I want it to start in a new line instead (this is because I want to take the whole last line and interpret the command from there). Is there a way to achieve that?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit New line after append

    If you can detect the end of output, e.g. the device sending a specific control character when its output is done, then you could append a new line or command prompt when you see that as part of the output.

    Otherwise it might be worthwhile to consider separating input and output, e.g. like in chat applications.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    FreddyKay (30th March 2014)

  4. #3
    Join Date
    Jun 2013
    Posts
    20
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTextEdit New line after append

    There is actually the standard \r\n character at the end of each line sended by the device. If I try to add that to my QStrings it is not making QtextEdit to start a new line. I tried switching is to plaintext but that did not work either. It seems to simply ignore the characters as they are not displayed either.

    Anyway, how can I actually start a new line? like: append("")? Or is there a more ele

    I will consider the separate input output. Was thinking about that as weill

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit New line after append

    Hmm, strange, \n should lead to a newline.

    Are you sure it is still part of the string passed to DisplayText()? I.e. that it has not been removed e.g. by the function reading from the device (can happen if one reads using readLine() or similar).

    Cheers,
    _

Similar Threads

  1. How do I set a QTextEdit to a specific line by line number?
    By Coolname007 in forum Qt Programming
    Replies: 8
    Last Post: 1st February 2013, 05:18
  2. Replies: 6
    Last Post: 1st October 2012, 14:05
  3. QTextEdit doesn't append text
    By Luc4 in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2010, 22:45
  4. How to add a new word to QTextEdit with "append"
    By yagabey in forum Qt Programming
    Replies: 8
    Last Post: 6th January 2008, 11:50
  5. QTextEdit::append help
    By tho97 in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10

Tags for this Thread

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.