Results 1 to 7 of 7

Thread: QDate Help pls

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QDate Help pls

    Hi,

    I have a QLineEdit in which the user can enter a date. Since the date field is birthday or anniversary it is highly possible that the user does not remember the year and therfore does not want to enter it.

    After validating I want to convert the date into dd MMMM yyyy or dd MMMM format.

    There are two problems here.

    1. Date Format:

    How to distinguish between 10 July 87, July 10 1987, 10 July 1987, 07-10-1987, 07-10-87,10-07-1987, 10-07-87 ..etc ? They are all valid dates. Just that they are entered in different format.

    2. Without year:

    User might enter 10 Jul, July 10, 10 July etc.. When I validate these dates, QDate will return invalid date and therefore I will not be able to convert it.

    Is there a way by which I give user maximum flexibility and still be able to identify the date he entered and convert it to the long month format ?

    Thanks a lot.

  2. #2
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDate Help pls

    hi..

    rather than giving a QLineEdit, why dont you provide the user with the dropdown list type of thing which would not allow the user to enter in any format but to choose from the given options... and then just take on each values and create a string in a format you want to..
    try to reduce the inputs from the user to minimum.. this way u can avoid the sort of errors which you listed down...

    kapil
    All you have to decide is what to do with the time that is given to you

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDate Help pls

    I dont want user to select any format. User should be able to enter as normal text (as he usually enteres the date. In different country people enter date in different format) and still be able to see finally the date in dd MMMM yyyy format if he had entered the year otherwise in dd MMMM format.

    How can I achieve this?

    Thanks a lot.

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QDate Help pls

    Sorry but why you use QLineEdit instead QDateEdit
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDate Help pls

    Quote Originally Posted by munna
    Hi,

    I have a QLineEdit in which the user can enter a date. Since the date field is birthday or anniversary it is highly possible that the user does not remember the year and therfore does not want to enter it.
    ...
    Thanks a lot.
    You can subclass a QDate object to use on your data entry form so that any sec tion of the date control can be blank or zeros, and the control will still only accept legal entries for all other possibilities. However, you cannot use a Date type in your database. It must be a varchar2(10) or something similar, accordng to the db you are using and you must convert between the two in your data I/O.

    I was given a similar problem. We have a form with a location for the birthdate. It gave space for "__/__/____", but some folks only put in their birth year, and some just the birth month and year. The subclass allowed our clerks to put in zeros or spaces for the month and day sections. But, it made doing SQL selects on the database a pain, so I reverted to the standard QDate control and a date type in the db. The percentage of people born on Jan 1st isn't very great, so we assume that a date of "01/01/yyyy" means that only the year was entered... etc, so only the year is printed on reports and other outputs.

  6. #6
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDate Help pls

    Quote Originally Posted by munna
    I dont want user to select any format. User should be able to enter as normal text (as he usually enteres the date. In different country people enter date in different format) and still be able to see finally the date in dd MMMM yyyy format if he had entered the year otherwise in dd MMMM format.

    How can I achieve this?
    I think you can't achieve this in the general case. For example, in most of Europe 9/11/2006 means November 9 while in America it would be interpreted as September 11. How do you intend to handle this? You have to force the user into some format or use locale information, maybe together with QComboBoxes as suggested by Kapil.

  7. #7
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDate Help pls

    hi...

    if you really want to use a QLineEdit sort of thing then i suppose you would have to write check conditions for most of the possible cases... you can also start a simultaneous thread or a check activated whenever the user enters anything in the line edit that he/she is doing it in proper format...
    You can use is line Edit isModified() function which on any input given to the line edit enable you to throw some event and this event which would be thrown would be a check specifier or say date processor which would check whether the user is giving in the date in proper format or not...
    this way you can force the user to give the input in a set format..
    if you want to give the user the privildge to give in any format then it would be very tough for you as you would have to write many conditions and still left with many exceptions which cannot be handled..
    so my suggestion would be either a combobox kinda thing or modified text check kind of thing...

    Kapil
    All you have to decide is what to do with the time that is given to you

Similar Threads

  1. QDate class extension
    By Carlton in forum Newbie
    Replies: 1
    Last Post: 22nd February 2009, 07:33
  2. QDate an locale setting
    By Boron in forum Qt Programming
    Replies: 5
    Last Post: 10th October 2008, 15:15
  3. Problems with QDate
    By cyberboy in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2008, 21:17
  4. Converting VC++ qreal to QDate
    By Krish_ng in forum Qt Programming
    Replies: 13
    Last Post: 12th January 2008, 19:23
  5. Two QDate issues
    By GreyGeek in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 02:09

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.