What's New in Qt 5.14: QCalendar

What's New in Qt 5.14: QCalendar

By Jeff Tranter

Qt 5.14 introduced a new class, QCalendar, which provides some useful functionality for localization of dates.

An instance of a QCalendar object maps a year, month and day number to a specific day using the rules of a particular calendar system. The supported calendar systems (as of Qt 5.14.1) are:

  • Gregorian (the default, and most widely used internationally)
  • Julian (an ancient Roman calendar with too few leap years)
  • Milankovic (a revised Julian calendar used by some Orthodox churches)
  • Jalali (the Solar Hijri calendar, also called Persian)
  • Islamic Civil (the tabular Islamic Civil calendar)

You can query an instance of QCalendar for various information such as a month name, whether it is a leap year, or whether it is a lunar calendar.

Specific calendar systems are implemented by back end plugins. The comments in the code indicate that there are more calendar systems defined by Unicode that could be supported in the future (e.g. Buddhist, Chinese, Coptic).

The Qt documentation does a good job of describing the APIs so I won't repeat that here. A wrote a small widget-based example program that exercises most of the QCalendar API. You can select from the available calendar systems, and then see the result of various methods. A couple screenshots are shown below.

Screen shot 1Screen shot 2

If you want to explore the QCalendar class, you can find the complete source code and project file here. It requires Qt 5.14.0 or later.