Results 1 to 11 of 11

Thread: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

  1. #1
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Hi, I don't want to prevent invalid entries in the date/time edits, this is what they do far too good. I want to enter invalid date strings into above widgets on purpose. Unfortunately they won't let me. For instance I want to have QDateEdit show --/--/-- when no valid date is available, e.g. when a date field in a database contains NULL. When I clear the widget, it resets itself to 1/1/00. Not too great since this is a valid date and even if it wasn't, it is not what I want.

    Any ideas regarding this problem?

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Hi,

    Create a line edit and set a mask/validator; This will work almost in 100%.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Quote Originally Posted by maverick_pol View Post
    Hi,

    Create a line edit and set a mask/validator; This will work almost in 100%.

    Kacper
    I already tried to set my own QLineEdit into the widgets, but they took total control over it and it behaved exactly the same. I will try to set my own mask/validator, but I would not be too surprised when this is replaced by the standard QDateTimeEdit ones.

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    HI,

    When you create a simple QLineEdit object you may enter different characters, and setting the mask will make the format look as you want. You can also set Validator based on regular expression to accept the chars you want.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #5
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Quote Originally Posted by maverick_pol View Post
    HI,

    When you create a simple QLineEdit object you may enter different characters, and setting the mask will make the format look as you want. You can also set Validator based on regular expression to accept the chars you want.

    Kacper
    Ok, true. I could 'reinvent' the whole QDateTime edit classes. However, if this really is necessary I'd say those classes have a serious design flaw. Being unable to set a 'no date set string' makes those classes for may applications unusable.

  6. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Hi,

    I would not say that this class has a design flaw. Let's say you have a base class accepting all characters. After a while you decide create a derived class accepting only a particular format and work with particular type of data. Would you then use the derived class object to work with particular data or would you rather use the base class object?
    QLineEdit can work they way you want.(mask/validation/format)
    QDataTime has a predefined format. It is hard to keep the same flexibility of a class when it is intended to be specialized/ intended to concentrate on a particular data type/format.

    What I am trying to say is that QDateTime was design to work with Date/time typical format data. You can change the format of displaying the data, but still the data entered need to be valid. You can show a '-' char as a separator, but still the '-' chat is not a part of the data.
    To create a custom format use QLineEdit as I said before.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  7. #7
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    I don't think we come to an agreement here.
    I think having a NULL value in an edit field is essential for many applications. Using QLineEdit directly practically means writing my own date edit classes from scratch. With the QDateTime classes Qt provides it would not be overly complicated, but IMHO for such a basic requirement it just should not be necessary.

  8. #8
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Hi,

    I agree with you up to a point : )
    In my opinion a date edit class is "obligated" to contain a date, still there should be a way of settings a "null" value, you're right here.
    I understand what you want to achieve, but still do not know why don't you use QLineEdit and use the settings you need.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  9. #9
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Quote Originally Posted by maverick_pol View Post
    Hi,

    ....but still do not know why don't you use QLineEdit and use the settings you need.

    Kacper
    Oh, this is exactly what I will do, have to do. As I said, with the other date/time classes Qt provides it is not overly complicated, but still the necessary validators are not trivial either, e.g. to prevent dates like 31/02/2008. If there were no classes like QDateTimeEdit/QDateEdit/QTimeEdit I'd happily do it. But as it is, I just feel like being forced to reinvent the wheel. I wanted to see whether there is a better way to do it, since I just can't imagine that I am the first one who has this problem. That's all.

  10. #10
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Yes, you're right you will have to do a bit of work, what should have been replaced by using a method or settings on QDateEdit/QTimeEdit.

    Thanks for the discussion : )

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  11. #11
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDateTimeEdit (QTimeEdit, QDateEdit) invalid input

    Yes, IMHO this IS STILL (Qt4.8) a design flaw: If you set a simple QDateEdit and connect it with a QDataWidgetMapper to a model which is connected with a SQL database, just put a NULL value into the database field that is read by the model and tied to the QDateEdit ->the edit will show 1/1/00 then which is NOT a NULL value.
    This is, on the first glance, not a big problem. But if you want to check in a form if there is already data in the widgets and COMPARE all the widgets' value fields (QLineEdit's "text" property etc) with the correlating database fields - the compare between the QDateEdit and the date DB field is just WRONG, it compares NULL with 1/1/00.

    So yes, design flaw IMHO. Struggling here too, I will do a QlineEdit with inputmask and validator. this way you can even allow more than one method to enter a date: 01/02/1987, 010287, 01021987 etc. to be all valid.

Similar Threads

  1. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22

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.