Bokambo
Bokambo

Reputation: 4480

How to intiliaze QTime in QT?

I have this in my header file:

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

How should timefrom be initialized?

Thanks.

Upvotes: 1

Views: 1662

Answers (3)

Kamil Klimek
Kamil Klimek

Reputation: 13130

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/

Upvotes: 0

O.C.
O.C.

Reputation: 6819

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.

Upvotes: 2

Mat
Mat

Reputation: 206679

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.

Upvotes: 1

Related Questions