You are comparing the value of the pointer not the value of the date object that it points to:
qDebug() << "Compare the pointers" << (a == b); // false, the two pointers are different i.e. they do not point at the same object
qDebug() << "Compare the objects" << (*a == *b); // true, the objects pointed at have the same value
QDate *a = new QDate(2011, 1, 1);
QDate *b = new QDate(2011, 1, 1);
qDebug() << "Compare the pointers" << (a == b); // false, the two pointers are different i.e. they do not point at the same object
qDebug() << "Compare the objects" << (*a == *b); // true, the objects pointed at have the same value
To copy to clipboard, switch view to plain text mode
Why use heap allocated QDates in the first place? You can quite happily store QDate in a QPair:
QList<QPair<QDate, int> > pairs;
pairs << qMakePair
(QDate::currentDate(),
1);
pairs << qMakePair
(QDate::currentDate(),
1);
qDebug() << pairs.count() << pairs.at(0).first << pairs.at(1).first
<< (pairs.at(0).first == pairs.at(1).first );
// outputs:
// 2 QDate("Thu May 19 2011") QDate("Thu May 19 2011") true
QList<QPair<QDate, int> > pairs;
pairs << qMakePair(QDate::currentDate(), 1);
pairs << qMakePair(QDate::currentDate(), 1);
qDebug() << pairs.count() << pairs.at(0).first << pairs.at(1).first
<< (pairs.at(0).first == pairs.at(1).first );
// outputs:
// 2 QDate("Thu May 19 2011") QDate("Thu May 19 2011") true
To copy to clipboard, switch view to plain text mode
Bookmarks