[Qt-interest] QDate compare
Duane
duane.hebert at group-upc.com
Fri Apr 29 15:28:54 CEST 2011
On 4/29/2011 8:33 AM, Robert Wood wrote:
> I'm struggling to do something really basic with comparing QDates. I
> just don't understand the documentation, so hope someone can help me!
>
> I have an array of structures, with one of the structure members being
> QDate as below:
>
> struct TransactionStructure
> {
> quint8 user;
> QDate transactionDate;
> QTime transactionTime;
> quint8 drawers;
> };
>
> struct TransactionStructure Transactions[2048];
>
> I have two QDateEdit objects on the ui which the user sets.
>
> I assumed I would be able to do this:
>
> if ((Transactions[i].transactionDate> ui.fromDateEdit)&&
> (Transactions[i].transactionDate< ui.toDateEdit))
>
> But this gives an error. The help goes on about operators such as this:
>
> QDate::operator> ( const QDate& d ) const
>
> I am guessing I need to use this kind of thing, but I just cannot work
> out how to use these operators. Google brings up zillions of hits, but
> they all just repeat the documentation and I can't find a simple example
> of how you actually use this in code.
>
> Would be most grateful if someone could demonstrate how to solve this! :~)
Have you tried getting the date object from the date edits and comparing
that?
This seems to work with 4.7.1:
QDate d1(1995, 5, 20); // May 17, 1995
QDate d2(1995, 5, 17); // May 20, 1995
QDateEdit de1(d1);
QDateEdit de2(d2);
if(de1.date() > de2.date()) {
qDebug("greater");
}else qDebug("less or equal");
More information about the Qt-interest-old
mailing list