Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved main widget emit signal once, but slot call multiple time

    General and Desktop
    3
    4
    235
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      s002wjh last edited by s002wjh

      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();
      subwidget_pt->show();

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

      signal is emit from another function

      void Main_Widget::load_data_button_pushed(){
      emit(mysig(void));
      }

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

      aha_1980 1 Reply Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @s002wjh last edited by

        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.

        regards

        Qt has to stay free or it will die.

        S 1 Reply Last reply Reply Quote 1
        • S
          s002wjh @aha_1980 last edited by

          @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.

          Pablo J. Rogina 1 Reply Last reply Reply Quote 1
          • Pablo J. Rogina
            Pablo J. Rogina @s002wjh last edited by

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

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 1
            • First post
              Last post