Results 1 to 5 of 5

Thread: QTime::currentTime().toString() + add. text

  1. #1
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTime::currentTime().toString() + add. text

    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

    Qt Code:
    1. myQTextEdit->append("the new inputline which should be added to the log");
    To copy to clipboard, switch view to plain text mode 

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

    I guess basicly i need QTime so i tried that:
    Qt Code:
    1. myQTextEdit->append(QTime::currentTime().toString());
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTime::currentTime().toString() + add. text

    What about:
    Qt Code:
    1. QString text = message + QTime::currentTime().toString();
    2. myQTextEdit->append(text);
    To copy to clipboard, switch view to plain text mode 

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

    ape (20th December 2007)

  4. #3
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTime::currentTime().toString() + add. text

    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.

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTime::currentTime().toString() + add. text

    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

  6. #5
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTime::currentTime().toString() + add. text

    Hi Marcel,

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

    But thanks again for the link and the offered help.

    Best regards
    ape

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. Replies: 1
    Last Post: 30th November 2007, 11:03
  4. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 10:02

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.