Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers
Accepted Solution

QDateTime question

Hey gang,

I was wondering why this doesn't work:

QDateTime dateTime;
dateTime = QDateTime::currentDateTime;
dateTime.date().setDate(dateTime.date().year(), dateTime.date().month(), 1);

But this does:

QDateTime dateTime;
dateTime = QDateTime::currentDateTime;
dateTime.time().setTime(0, 0, 0, 0);

In other words, using dateTime.date() doesn't seem to work, but dateTime.time() does.

Is this a bug?

Thx,

J

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QDateTime question

[ Edited ]

Both of them shouldn't work: they return QDate or QTime by value, so modifying them shouldn't modify the original variable.

currentDateTime is a function, it shouldn't compile without braces.

The correct syntax is:

QDateTime dateTime = QDateTime::currentDateTime();
dateTime.setDate(QDate(2012, 12, 20));
dateTime.setTime(QTime(0, 0));

 

Or

QDateTime dateTime(QDate(2012, 12, 20), QTime(0, 0));

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers

Re: QDateTime question

Thank you!
bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com