Important: Please read the Qt Code of Conduct -

QPushButton on signal for 500ms every pressed action

  • Hi, because we use QmodBus and some modbus register is write and cancel in a short time, I try to connect these action to a qpushbutton not toggled .....
    Actually I use Qpushbutton and Toggled event, than I use lambda function and timer, So the user press the toggle button, and after 500 or 1000ms the toggled button become unpressed again. In these time I can write my modbus register, bring the modbus answer than,,, when toggle button is unpressed cancel that modbus register ..... so the slave modbus device "see" a signal similar to a phisical button (or a signal up for 500-1000ms ..... if the waiting and response times of the modbus are not taken into account .... more or less the real time that the slave device see the register up, is 300/400 or 800/900ms, but these is not part of question).

    Is it possible to use some new feature of qt creator or qt 5.10 that allows to use a pushbutton and keep its signal high for a desired time?


  • Lifetime Qt Champion

    Qt signals are not on for a duration, its simple a one shot event. ( often a function call)
    so there is no concept of be "high" for the button.

    However, how do you keep the signal otherwise ?

    QPushbutton do have a auto repeat feature, where can continuously send signal if button is being held.
    You can use that feature to emit signal over and over but im not sure that is that you need?

  • @mrjj sorry for late reply. No autorepeat feature is not good for my pourpose. I know the one shot property of push button .... but I need a 2 state signal with time delay .... so when the user press the button the signal go On and after 500ms tourn Off again whitout user perform ant type of action.

    only these .... actually i use oneshot timer for obtain these result.


  • Lifetime Qt Champion

    @gfxx I would have used a timer also, it looks like the right solution.

  • Lifetime Qt Champion

    @gfxx Can you please mark this thread as SOLVED? Thanks!

Log in to reply