开发者

How to intiliaze QTime in QT?

开发者 https://www.devze.com 2023-03-10 18:39 出处:网络
I have this in m开发者_Python百科y header file: explicit AccessSchedule(QWidget *parent = 0,QString item = \"\",QTime timefrom )

I have this in m开发者_Python百科y header file:

explicit AccessSchedule(QWidget *parent = 0,QString item = "",QTime timefrom ) 

How should timefrom be initialized?

Thanks.


Have you ever considered using QTime::currentTime() as your default parameter ? i.e

explicit AccessSchedule(QWidget *parent = 0,QString item = "",QTime timefrom=QTime::currentTime() ) 

This way you don't have to check if the object isValid() or isNull() which I think makes code more readable. But it is your call of course.


If you want a default time, you can write:

explicit AccessSchedule(QWidget *parent = 0,QString item = "", QTime timefrom = QTime(11, 45));

timefrom will represent 11:45. If you just put:

..., QTime timefrom = QTime());

timefrom will be a "null" time object, i.e. it's isNull() method will return true and isValid() will return false.


Your function arguments are in wrong order. Arguments with default value should be ALWAYS at the end of argument list. Read this: http://www.learncpp.com/cpp-tutorial/77-default-parameters/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号