main widget emit signal once, but slot call multiple time

  • my design has main widget and a sub widget. I use qt push button to open the subwidget. but when i close subwidget (x sign) and use the button to open i again, my signal emit once buy my slot function run twice. I close subwidget, and open again via qt push button. now my signal emit once, but my slot function run three time. any ideas

    void Main_Widget::launch_sub_widget_button_pushed(){
    subwidget_pt = new sub_Widget();

    connect(this, SIGNAL(mysig() ),
    subwidget_pt, SLOT(myslot() ) );

    signal is emit from another function

    void Main_Widget::load_data_button_pushed(){

    i try subwidget_pt->close() but it close all my widget including the main one.

  • Qt Champions 2018

    hi @s002wjh,

    you run the connect statement multiple times, therefore the slot is executed multiple times.

    Solution: only connect once, then emit as often as you like.


  • @aha_1980

    thanks, i saw it will disconnect automatically when i close the sub-widget, guess not. I didn't properly run the destructor, now its working after i run the destructor.

  • @s002wjh if your issue is solved, please don't forget to mark you post as such. Thanks.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.