PDA

View Full Version : QTextEdit New line after append



FreddyKay
30th March 2014, 12:41
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:



void DisplayText(QString msg){
ui.textEdit->append(msg);
}


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?

anda_skoa
30th March 2014, 12:56
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,
_

FreddyKay
30th March 2014, 13:05
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 ;)

anda_skoa
30th March 2014, 15:23
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,
_