Results 1 to 20 of 27

Thread: display time as as string ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default display time as as string ?

    How can I display trme as a string ?
    Could someone give me some code to be able to do that ?
    I am using a TimeEdit window. So suppose someone edits it. I would like the editted time to show up in a mesage box.

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: display time as as string ?

    QString str = "time";


    sorry couldn't resist.

    RTFM
    Qt has really good documentation. From within Qt Creator, Click on Help-Index and type QDateTime - that should help you on your way.

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: display time as as string ?

    see QTime::toString()

  4. #4
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: display time as as string ?

    Hi

    Hers the code for you

    Qt Code:
    1. QTimeEdit timeEdit;
    2.  
    3. QString timeInString = timeEdit.time().toString("h:m:s ap");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    Well it does it . It displays 12:00 in a message box.
    But it does not display the update time when the user edits the EditTime box.
    I tried
    Qt Code:
    1. QString timeInString = QString timeInString = timeEdit.timeChanged().time().toString("h:m:s ap");
    To copy to clipboard, switch view to plain text mode 
    But it gave a parameter error on timeChanged .
    I am flumoxed here.

  6. #6
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display time as as string ?

    You can't use timeChanged() the way you do.
    It's a [signal] and you must connect it to a [slot].

  7. #7
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    ok. What i need is some way to retrieve the text from QTimeEdit and display it in a messagebox.

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display time as as string ?

    A pointer of QTimeEdit in the messagebox

  9. #9
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    Here is the code:
    Qt Code:
    1. void calendartime:: display_message()
    2. {
    3. QMessageBox msgbox;
    4. QTimeEdit *timeEdit;
    5. QString timeInString = timeEdit.time().toString("h:m:s ap");
    6. msgbox.setText(timeInString) ;
    7. msgbox.exec();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    I get the following error:
    calendartime.cpp:44: error: request for member 'time' in 'timeEdit', which is of non-class type 'QTimeEdit*'

  10. #10
    Join Date
    Jun 2007
    Location
    Massachusetts, USA
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display time as as string ?

    Try
    Qt Code:
    1. QString timeInString = timeEdit->time().toString("h:m:s ap");
    To copy to clipboard, switch view to plain text mode 
    (Note "timeEdit->" instead of "timeEdit.".)

  11. #11
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: display time as as string ?

    I get calendartime.cpp:44: error: base operand of '->' has non-pointer type 'QTimeEdit'
    Then I tried this code
    Qt Code:
    1. void calendartime:: display_message()
    2. {
    3.  
    4.  
    5. QMessageBox msgbox;
    6. QTimeEdit *timeEdit;
    7. QString text = timeEdit->time().toString("h:m:s ap");
    8.  
    9. msgbox.setText(text);
    10. msgbox.exec();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    and it crashed withc process id 4192. I suspect this has to something with the pointer to QTimeEdit.
    I am starting to think it can't be done..
    Last edited by Petr_Kropotkin; 27th January 2010 at 22:41.

Similar Threads

  1. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 16:47
  2. How to display individual character of a string?
    By cooper in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2009, 05:19
  3. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55
  4. QTableView does not display time string correctly
    By ad5xj in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2007, 20:35
  5. Display the camera frame in real time
    By alex_lue in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2007, 10:31

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
  •  
Qt is a trademark of The Qt Company.