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

Internal QDateTime validator returns invalid when validating a string containing AM/PM on some QLocales

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • None
    • 5.5.0
    • None
    • Windows 8.1
      Visual Studio 2013
      Qt 5.5.0 static

    Description

      Disclaimer

      This is probably not the intended way to check the validation state of Date Time Edits, but this has worked up to Qt 5.3 (not tested with Qt 5.4) but fails with Qt 5.5:

      Background

      Our program recursively checks the validators of all QLineEdits in the currently opened GUI mask. QDateTimeEdit has such a QLineEdit child with a QSpinBoxValidator set and is thus part of our validation process.

      Problem

      When using e.g. a English/UK or German/Germany locale, the "AM/PM" part is now displayed in a QDateTimeEdit as "A.M./P.M." or "VORM./NACHM.". (I'm a bit surprised the DateTimeEdit does not automatically use the 24h format for the German locale anyway.)
      QDateTimeParser::sectionMaxSize() however returns a size of 2 for these cases and thus the string is cut down to "A." or "VO" for validation. Later on, this produces an invalid validation result, as the date time string does not match the date time format.

      Code

      Here is some code for reproducing the problem:

      void testValidator( QDateTimeEdit* pDateTimeEdit, QLocale::Language language, QLocale::Country country )
      {
          pDateTimeEdit->setLocale( QLocale( language, country ) );
          // Search for a QLineEdit child of the QDateTimeEdit and execute its validator
          for( auto pChild : pDateTimeEdit->children() )
          {
              auto pChildLineEdit = dynamic_cast<QLineEdit*>(pChild);
              if( !pChildLineEdit ) continue;
      
              int dummy = 0;
              qDebug() << pChildLineEdit ->text() << ":" << pChildLineEdit ->validator()->validate( pChildLineEdit ->text(), dummy );
          }
      }
      
      int main( int argc, char *argv[] )
      {
          QApplication dummy( argc, argv );
      
          QDateTimeEdit dateTimeEdit;
          dateTimeEdit.setDateTime( QDateTime::currentDateTime() );
          
          testValidator( &dateTimeEdit, QLocale::English, QLocale::UnitedStates );
          testValidator( &dateTimeEdit, QLocale::English, QLocale::UnitedKingdom );
          testValidator( &dateTimeEdit, QLocale::German, QLocale::Germany );
      
          // Output:
          // "8/18/2015 11:14 AM" : 2
          // "8/18/2015 11:14 A.M." : 0
          // "8/18/2015 11:14 VORM." : 0
          return 0;
      }
      

      Note: 2 = Valid, 0 = Invalid

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              StHummel86 Stefan Hummel
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes