PDA

View Full Version : QTime::currentTime().toString() + add. text



ape
20th December 2007, 10:31
Hi,

i am using multi-line QTextEdit as logging-window
-> all user inputs should be logged and displayed in this scrollable box.

Basicly that works as supposed in my testing-application.
Each time i need to add a new text i am using something like that



myQTextEdit->append("the new inputline which should be added to the log");


Today i had the idea to add a timestamp for each new entry.

I guess basicly i need QTime so i tried that:


myQTextEdit->append(QTime::currentTime().toString());


Well that gives a new line with a timestamp...nice but not as need it.
I need a way to add a single line with the generated TimestampString and my custom defined string like in the first code-block.

Question 1:
Should i concat those strings somehow ?

Question 2:
Is the basic idea regarding my Timeconversion to String a good idea, or should i try it somehow diffrent ?

Best regards in advance
ape

marcel
20th December 2007, 10:33
What about:


QString text = message + QTime::currentTime().toString();
myQTextEdit->append(text);

ape
20th December 2007, 10:42
Hi Marcel,

yeah with some small cosmetic change exactly what i needed.
guess i lack some basic c++ knowledge.

but basicly the idea with currentTime().toString was ok, right ?
Or is there any other method to get a timestamp as String which you would prefer ?

Thank you very much for the fast & helpful response.

marcel
20th December 2007, 10:54
You can also format the time. The format parameter can be passed to toString. Take a look at available format strings: http://doc.trolltech.com/4.3/qtime.html#toString

ape
20th December 2007, 11:51
Hi Marcel,

I guess you misunderstood my "with some cosmetc changes"-part.
i already did those small changes :D

But thanks again for the link and the offered help.

Best regards
ape