3

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?

Ingo Holder
  • 37
  • 1
  • 5
  • 3
    maybe a problem with your mouse? – Karsten Koop May 19 '16 at 07:23
  • 1
    Maybe there is another object on top of it which has a bounding rectangle that is extending over the button, preventing you from clicking it? – mike510a May 19 '16 at 08:00
  • @ Karsten Koop i have thought of this, but unlikely since i have given my code to a friend and he has the same issues with it. @Mike Nickaloff How would i find out? I just have added it to the UI in the Designer and given the Widget a Layout thats it. – Ingo Holder May 19 '16 at 08:03
  • Try connecting your button to a different slot, where you only print a debug message. – thuga May 19 '16 at 08:09
  • To confirm that you really clicked on the button - When you click on the button do you see active focus on the button ? and still that your slot routine is not getting invoked ? – user12345 May 19 '16 at 09:33
  • @thuga have done that, same result occassionally it doesn't send – Ingo Holder May 19 '16 at 10:35
  • @user12345 with each click i see the button have an animation to go "down" like it is pushed. This happens always to 100% but still it doesn't fire the function even if its another function with just a qDebug() – Ingo Holder May 19 '16 at 10:36
  • @KarstenKoop try clicking on the object in the UI Designer and then right clicking on it, and then clicking on "Bring to Front" This will ensure that the object is on top of other objects in the UI – mike510a May 23 '16 at 01:23

1 Answers1

2

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.

user12345
  • 661
  • 8
  • 34
  • Any help that gets me closer to solve the problem helps! So thank you for that. Real nice way to debug i have to say. After some testing your code really helped me!! And i will keep that in my head to debug it like that .Somehow it liked "pressed()" more than "clicked()" – Ingo Holder May 19 '16 at 12:22
  • 2
    Glad to know that it helped. Just on side note: `Pressed:` event is generated when you push down the mouse button. `Released:` event is generated when you release the mouse button (which has been pressed down before) `Clicked:` event is generated when a mouse button Pressed & Released. – user12345 May 19 '16 at 12:42
  • 2
    also,, the Clicked event will only fire if the press and release actions happen without the object losing focus - so if other UI elements steal focus between the press and release, the click event wont fire. Maybe this is your issue? – mike510a May 23 '16 at 01:25