How to use QTimer connect without Object and without slot



  • Could you please share details on using connect function call without object and without slot.

    When I am trying below connect call: where in i want to use QTimer without a class object and without slot
    QObject::connect(pTimerUpdateScheduleTimeout, &QTimer::timeout,NULL, UpdateScheduleEvent());

    I am getting below error:
    error: invalid use of void expression
    QObject::connect(pTimerValidateScheduleTimeout, &QTimer::timeout,NULL, ValidateScheduleEvent())

    could you please help on above error.

    Thanks,
    Mrudula


  • Qt Champions 2018

    ValidateScheduleEvent() calls the function and pass the result back to connect as an argument. what you want is taking the function pointer: QObject::connect(pTimerValidateScheduleTimeout, &QTimer::timeout,&ValidateScheduleEvent);



  • Hi,
    You can use QTimer with lamda functions like this.

    connect(pTimerValidateScheduleTimeoutr, &QTimer::timeout, []() {
    ValidateScheduleEvent();
    });

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.