Search code examples
c++qtsignals-slots

Qt: Multiple windows showing on button press


connect(ui->button,SIGNAL(pressed()),this,SLOT(showWindow2()));

// Slot
void Window1::showWindow2()
{
    Window2*cal = new Window2();
    cal->show();
}

There are 2 Window2 instances showing on top of Window1. I believe it is sensing a double tap on the capacitive touch screen and is triggering the pressed signal twice. I am having trouble finding a proper solution to this. I tried a delay after it was pressed once, and just return from the slot if the delay has not expired yet. But i do not believe this is a good solution. Does anyone know how to go about this?


Solution

  • Try using another QPushButton signal (i.e. clicked):

    connect(ui->button,SIGNAL(clicked(bool)),this,SLOT(showWindow2()));