Unsolved Singleton QDateTime Issues
-
@Simof
Hi,
try to remove Q_OBJECT -
And what do you think you gain with this class??
-
@Christian-Ehrlicher said in Singleton QDateTime Issues:
And what do you think you gain with this class??
I would include this class in all widgets and use this instead of System Clock
QString dateTimeStr = Calendar::GetInstance().toString("\"yyyy-MM-dd hh:mm\""); dateTimeLbl = new QLabel(dateTimeStr);
-
@Simof You should read https://doc.qt.io/qt-5/qdatetime.html#QDateTime
-
@Simof Why don't you simply use static https://doc.qt.io/qt-5/qdatetime.html#currentDateTime instead of introducing a singleton?!
-
@CP71 said in Singleton QDateTime Issues:
@Simof
Hi,
try to remove Q_OBJECTNow it works correctly, thanks
-
@jsulm said in Singleton QDateTime Issues:
@Simof Why don't you simply use static https://doc.qt.io/qt-5/qdatetime.html#currentDateTime instead of introducing a singleton?!
Can I define a static QDateTime in main mainwindow and use it in all widgets included inside itself?
-
@Simof said in Singleton QDateTime Issues:
Can I define a static QDateTime in main mainwindow and use it in all widgets included inside itself?
Why do you need a static QDateTime? What is your use case?
-
-
@CP71 said in Singleton QDateTime Issues:
@Simof
Hi
As @jsulm says , you don't need a singleton and static class to do this if you have to do something else that we don't know.
To do this you can write QString text = QDateTime::currentDateTime().toString(""yyyy-MM-dd hh:mm""); without declare new class o singleton class.My application works on embedded device and the system time is not reliable so I would use a RTC (Real Time Clock IC) such a main clock.
I could use QDateTime::currentDateTime().toString(""yyyy-MM-dd hh:mm"") only if I can set my system time equal to RTC time but I don't know if it's possible
-
@Simof
So don't use rawcurrentDateTime
. If you don't want to repeatedly read RTC (I don't do embedded, maybe that is expensive or inconvenient?), read it once and getcurrentDateTime()
at same time, calculate offset difference, use that adjustment amount tocurrentDateTime()
from then onward?