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
New Developer
Posts: 19
Registered: ‎12-06-2013
My Device: Q5
My Carrier: WIFI

Update QDate in app

Hi all,

 

In my app using QDate worked but when run my app in 11:59 PM to 12:00 AM "worked when close app and open again" nothing update date so I worked QTimer every 1 second update, but not work ): I'm sure the QTimer work.

 

code:

 

void ApplicationUI::update() {
	QTimer::singleShot(1000, this, SLOT(dateUpdate()));

}

QString ApplicationUI::dateUpdate() {
    return QDate::currentDate().toString(Qt::DefaultLocaleLongDate);
}

 

My question is: How do I make QDate Update when a new day without Close app?

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Update QDate in app

There are not really any triggers for Date's yet AFAIK you could invoke using the calander but I always think that is a little clumsy.

 

Options are;

 

  1) Long running headless checking date/time (If needed outside of app running)

 

  2) As you are doing use a QTimer to periodically check

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 226
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB/C, Z10
My Carrier: Sonera, Saunalahti

Re: Update QDate in app

You are using a singleShot timer, it will only fire once and then stop. See http://qt-project.org/doc/qt-4.8/qtimer.html#singleShot-prop

 

What you need to do is something like this, see http://qt-project.org/doc/qt-4.8/qtimer.html#details

 

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);

 

 



Kaj-Michael Lang, Home.
Author of: Onki and RetroPlayer
New Developer
Posts: 19
Registered: ‎12-06-2013
My Device: Q5
My Carrier: WIFI

Re: Update QDate in app

@BBSJdev

 

Not good wtth calendar.

I think no need to use headless.

Use QTimer but did not worked "Read more down ".

 

@oniongarlic

 

I used it but it did not work as well.

 

My code:

 

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updatedate()));
timer->start(1000);

updatedate();

QString ApplicationUI::updatedate() {
    return QDateTime::currentDateTime().toString(Qt::DefaultLocaleLongDate);
}

 

^ Like this when use private slots in app.h:

 

private slots:

QString updatedate();

 

Not work in my app and nothing show any thing but when use like this:

 

Q_INVOKABLE QString updatedate();

 

show date in app but not updated.

Developer
Posts: 226
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB/C, Z10
My Carrier: Sonera, Saunalahti

Re: Update QDate in app

You need to update your UI from the timer. Or use a property that you update and then emit the change notification.


Kaj-Michael Lang, Home.
Author of: Onki and RetroPlayer
New Developer
Posts: 19
Registered: ‎12-06-2013
My Device: Q5
My Carrier: WIFI

Re: Update QDate in app

[ Edited ]

@oniongarlic

 

I did using emit but how update label in QML when get emit from C++.

 


 

 

Plase can any one make full code for how do this.