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
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
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
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

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
Please use plain text.
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: QDateTime question

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