-2

I have Qt 5.6 and I'm using the pressed signal of a button witch then shows a dialog. unfortunately the button of dialog is not clicked in the first time but the second click is working perfectly. you can test this situation by showing a QMessageBox::information in a on_someButton_pressed slot.

a.tabatabaei
  • 304
  • 3
  • 16
  • What signal do you connect to - [clicked](http://doc.qt.io/qt-4.8/qabstractbutton.html#clicked) or [pressed](http://doc.qt.io/qt-4.8/qabstractbutton.html#pressed) ? – mvidelgauz Aug 25 '16 at 16:57
  • as I mentioned in the question its **pressed** signal. – a.tabatabaei Aug 25 '16 at 17:01
  • 1
    Worked for me just as expected, dialog opening on pressing mouse button down... And all I did was to create a widget project, add a push button in designer, then "Go to slot...": `void MainWindow::on_pushButton_pressed() { QMessageBox::information(this, "INFO", "Text...", QMessageBox::Ok); }` – hyde Aug 25 '16 at 17:32
  • 1
    Please post your code so we can determine if there are issues with it. – Peter K Aug 25 '16 at 19:44

1 Answers1

0

Sorry, can't reproduce: works for me. And you should have written this test case. It's almost less words to code it up than to describe the problem.

#include <QtWidgets>
int main(int argc, char ** argv) {
   QApplication app{argc, argv};
   QPushButton button{"Press me"};
   button.setMinimumSize(300, 150);
   button.setFont(QFont{"Helvetica", 20});
   QObject::connect(&button, &QPushButton::pressed, [&]{
       QMessageBox::information(&button, "Yes!", "You pressed me.");
   });
   button.show();
   app.exec();
}

As an aside, you should be using the clicked() signal, not the pressed() signal. Usability suffers if you use the latter.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Thanks for the reply. But maybe I didn't explain the situation well. The problem is not the push button 'button' itself but the push button in the dialog. For example the OK button in the 'QMesageBox'. You should click OK button twice to close the information dialog. Thanks again for your help. – a.tabatabaei Aug 26 '16 at 06:24
  • Have you run the test case above? It works just fine! – Kuba hasn't forgotten Monica Aug 26 '16 at 13:02
  • Sorry but I don't have any problem with it in Windows. But in beagle bone black and a touch screen I have this issue. Qt version 5.6, tool chain linaro 4.9, cross compiling from Ubuntu 16.04. I think the event is not handled in Qt event handler the first time. – a.tabatabaei Aug 27 '16 at 08:48
  • You assume that the platform delivers the event to Qt to begin with. I'd treat it as an unsubstantiated assumption unless you have hard proof otherwise (i.e. you catch the event as it's delivered to Qt's native event handler, and then fail to trace it to the widget). – Kuba hasn't forgotten Monica Aug 28 '16 at 00:11