Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. main widget emit signal once, but slot call multiple time
Forum Updated to NodeBB v4.3 + New Features

main widget emit signal once, but slot call multiple time

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 447 Views 1 Watching
  • 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 Offline
    S Offline
    s002wjh
    wrote on last edited by s002wjh
    #1

    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_1980A 1 Reply Last reply
    0
    • S 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_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • aha_1980A aha_1980

        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

        S Offline
        S Offline
        s002wjh
        wrote on last edited by
        #3

        @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. RoginaP 1 Reply Last reply
        1
        • S s002wjh

          @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. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

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

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved