开发者

How to intiliaze QTime in QT?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜