Garmaine Staff asked 2 years ago

I need to make an adapter for QTimeEdit to use it with time_t in:

  1. constructor QTimeEdit(time_t)
  2. void setTime(time_t)
  3. time_t time() I did 1. and its working.
class QTimeEditAdapter: public QTimeEdit {
public:
    QTimeEditAdapter(time_t t) {
        tm1 = t;
        tm *ltm = localtime(&tm1);
        int hours = ltm->tm_hour;
        int min = ltm->tm_min;
        this->setTime(QTime(hours,min));
    }
private:
    time_t tm1;
};
int main(int argc, char *argv[])
{
    time_t tm1;
    tm1 = time(NULL);

    //other qt widgets code

    QTimeEdit* timeEdit = new QTimeEditAdapter(tm1);

    //more other qt widgets code

But if I'm adapting setTime by adding

void setTime(time_t t1)

to the class its redefines setTime and I'm getting mistakes from both constructor and method setTime. I didn't found any other method to set time in QTimeEdit but I guess there must be a way better than my