Can't figure out how to specify format for QDate::fromString call where the string is a date with one or two digits for day and month. For example: 1/12/2018 or 01/12/2018, or 1/1/2018 vs 01/01/2018. Advice is greatly appreciated.
Thanks
Can't figure out how to specify format for QDate::fromString call where the string is a date with one or two digits for day and month. For example: 1/12/2018 or 01/12/2018, or 1/1/2018 vs 01/01/2018. Advice is greatly appreciated.
Thanks
I am afraid that you have to call 4 times QDate::fromString (with different params for each case) and verify it by QDate::isValid...
So don't use QDate::fromString().
Qt Code:
QDate date; if ( dateList.length() == 3 ) { int month = dateList.at( 0 ).toInt(); int day = dateList.at( 1 ).toInt(); int year = dateList.at( 2 ).toInt(); date.setDate( year, month, day ); } else // errorTo copy to clipboard, switch view to plain text mode
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks