Search code examples
c++qtbuttonclickqpushbutton

Qt - Pushbutton click not always working


I have a QT App and have currently added a new QPushButton. I have connected the button properly with:

QObject::connect(ui->myButton, SIGNAL(clicked()), this, SLOT(SendResetEchoRequest()));

Most of the time it is working when i click it calls the function. But sometimes it doesn't register my click. Sometimes i need up to 5-10 clicks to make the function fire once and i don't know why.

 

To be sure this is a problem with the Button / Click i have tried using the function on key UP like this:

if(GetAsyncKeyState(VK_UP)){
    SendResetEchoRequest();
}

This works 100% perfectly fine. And when i press my UP key it triggers the function.

Anybody got an idea why sometimes it doesn't register my click?


Solution

  • I am not sure if it will be of any help, I would like to suggest a quick exercise to examine.

    You can connect to the signals pressed and released and in the slot routine try to set the button text to "Pressed"and on button release it should go back to "<your button text>"

    QObject::connect(ui->myButton, SIGNAL(pressed()), this, SLOT(setbuttonPressed()));
    QObject::connect(ui->myButton, SIGNAL(released()), this, SLOT(setbuttonReleased()));
    
    setbuttonPressed() {
    ui->myButton->setText("Pressed"); }
    
    setbuttonReleased() {
    ui->myButton->setText("My Button"); }
    

    This way when you see that occasional problem you can examine if QAbstractButton or QPushButton class ever signals anything. This is just my thought to debug what's going on, may not be the solution to your problem.