#include#include int main() { QDate currentDate = QDate::currentDate(); QDate futureDate(2022, 1, 1); int days = currentDate.daysTo(futureDate); qDebug() << "Days to New Year's Day 2022: " << days; return 0; }
#includeIn this example, we use a for loop to iterate through all the dates from January 1, 2021 to December 31, 2021. For each date, we call the daysTo function on it, passing in December 31, 2021. We output the date and the number of days to the end of the year to the console. The QDate class is part of the Qt Core module, which is included in the Qt library.#include int main() { QDate startDate(2021, 1, 1); QDate endDate(2021, 12, 31); for (QDate date = startDate; date <= endDate; date = date.addDays(1)) { int days = date.daysTo(endDate); qDebug() << date.toString("yyyy-MM-dd") << "days to end of year: " << days; } return 0; }