Results 1 to 4 of 4

Thread: Casting QDate to QDateTime

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Casting QDate to QDateTime

    Is it possible?
    I need the QCalendar "clicked" signal,which emits a QDate....BUT I need a QDateTime. Is it possible to cast it to QDateTime?

    As a sidenote: Does QDate provide a method to convert from its internal data format to milliseconds?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Casting QDate to QDateTime

    Does QDate provide a method to convert from its internal data format to milliseconds
    QDate represents a date, it stores no informations about the hours or minutes. For example, someone told you to met him at 26 january but forgot to tell you the exact time, can you somehow "extract" the time of meeting given the date alone ? Can you convert the "internal data format" of 26 January to "miliseconds" ?
    I need the QCalendar "clicked" signal,which emits a QDate....BUT I need a QDateTime.
    Then create a slot that accepts QDate, and inside it emit a signal with QDateTime, created using the received QDate and the needed time component. And use that custom signal instead original QCalendar signal.

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

    alitoh (25th August 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Casting QDate to QDateTime

    Ah, the second option did not occur to me. Good one.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Casting QDate to QDateTime

    QDateTime has a conversion constructor that accepts a QDate. The resulting QDateTime has the time component set to midnight (00:00:00.000). It also has a constructor that takes a QDate and a QTime and puts them together if you want to control the time component.

Similar Threads

  1. casting qvector element
    By rivci in forum Newbie
    Replies: 1
    Last Post: 4th April 2011, 13:58
  2. Casting variables
    By axisdj in forum Newbie
    Replies: 1
    Last Post: 6th September 2010, 17:00
  3. View QDate and QDateTime in VisualStudio debugger.
    By r2d2u2 in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2010, 17:23
  4. Casting QGraphicsItem
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 23:56
  5. Extending QDate, QTime and QDateTime
    By jamadagni in forum Qt Programming
    Replies: 8
    Last Post: 24th March 2006, 15:51

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.