Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9431

QDateTimeEdit's lack of support of dates lower than 100-01-01 causes problems when using database data...



    • Type: Bug
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Out of scope
    • Affects Version/s: 4.6.1
    • Fix Version/s: Some future release
    • Labels:
    • Environment:
      Linux Kubuntu 9.04 "Linux ixm-laptop 2.6.28-17-generic #58-Ubuntu SMP Tue Dec 1 18:57:07 UTC 2009 i686 GNU/Linux"


      Hi there,

      For the past few weeks, I've been trying to develop an application that connects to a database in which null dates are stored. I've found that QDateTimeEdit classes cannot handle dates lower than 100-01-01. This problem has already been reported but I wanted to highlight the particular case of database users like me.
      This is very annoying since it means that we currently have to find various ways to make the program work. For example, I'm now creating a little patient record manager. I have to store people's decease date which some of the patients (good for them) do not have. This is simply done by assigning the null date 0000-00-00 to people who are not dead. QDate handles this very well since isValid() returns false.

      However, for a reason I don't get, QDateTimeEdit cannot. If I try to call setDate(QDate(0000, 00, 00)); the result is that the date displayed in the QDateEdit is 2000-01-01 (btw this is new since before (when ?) the date was something like 1752-09-14). This is not acceptable for a patient record since this date is way to close to now. Usually, I just say 100-01-01 is the null date since the probability to have a patient dead back then is not that big and I accept the fact that 100-01-01 is displayed in my software...

      But I'm also working with models, views and QDataWidgetMapper and now it's becoming really annoying. Let's say I have class A which contains QLabels and a QDataWidgetMapper and class B which inherits QSqlQueryModel. I map the labels to various sections of my model and everything's fine.
      Well not everything, when a QDate is mapped to a QLabel and the QDate isNull(), the label content does not change (if the text that was shown was "LabelLOL" it stays "LabelLOL"). For now, I just display nothing in the QLabel before the mapper populates the widget. But if I need to edit the date and I use QDateEdit, I'm forced to change my model so that data() returns a QDate(100, 1, 1) if the date isNull()... But then again, I have to check I try to commit changes because otherwise, my database will soon be full of 100-1-1 dates.

      I suggest that the QDateEdit should be fixed as soon as possible and that, by the mean of a flag, coders could choose to allow null dates to be shown and entered by the user.

      I'd really appreciate if this issue could be fixed or that a quick hack could be done (like as I said let the developer choose the state of a flag and allow the null date (not even support dates < 100-1-1) before Qt 4.5

      Thank you very much for your understanding and sorry for the huge text :/



        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            Unassigned Unassigned
            ixm Maximilien Renard
            1 Vote for this issue
            2 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes