PDA

View Full Version : Casting QDate to QDateTime



alitoh
25th August 2011, 20:59
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?

stampede
25th August 2011, 23:11
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.

alitoh
25th August 2011, 23:12
Ah, the second option did not occur to me. Good one.

ChrisW67
26th August 2011, 02:22
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.