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
- relates to
-
QTBUG-55151 Cannot change times in QDateTimeEdit if format includes AM/PM and widget locale != translator language
-
- Closed
-