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. Regarding Signals and Slots
Forum Updated to NodeBB v4.3 + New Features

Regarding Signals and Slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
34 Posts 6 Posters 3.4k Views 2 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
    Shruthi
    wrote on last edited by
    #21
    This post is deleted!
    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #22

      Hi
      if the goal is to block signals then as jonB says you must do

      ui->tableWidget->blockSignals(true);
      xxxxx
      ui->tableWidget->blockSignals(false);

      not reverse

      1 Reply Last reply
      1
      • S Shruthi

        This post is deleted!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #23

        @Shruthi
        As @mrjj has just said. All you were supposed to do was swap one false with one true.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Shruthi
          wrote on last edited by
          #24

          @JonB @mrjj Ya I tried swapping, but it's still the same.

          JonBJ 1 Reply Last reply
          0
          • S Offline
            S Offline
            Shruthi
            wrote on last edited by
            #25

            Can we achieve this without using blocksignals? If so, what changes needs to be done? @JonB @mrjj

            1 Reply Last reply
            0
            • S Shruthi

              @JonB @mrjj Ya I tried swapping, but it's still the same.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #26

              @Shruthi
              So your slot is firing while you are initialising. You have a couple of choices:

              • Here you also want to block signals during fillTableWidget(), so add that; or

              • Do not connect() the slot till after fillTableWidget() has done its work. If you are using Designer's autoconnect of slots change over to your own connects.

              S 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #27

                Just one question - what should fillTableWidget() do at all (apart from the fact that it does not compile at all)? When rowCount() is greater than 0 then empty QTableWidgetItem's are set, nothing more.

                Please provide a minimal, compilable example to reproduce your issue!

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                S 1 Reply Last reply
                0
                • JonBJ JonB

                  @Shruthi
                  So your slot is firing while you are initialising. You have a couple of choices:

                  • Here you also want to block signals during fillTableWidget(), so add that; or

                  • Do not connect() the slot till after fillTableWidget() has done its work. If you are using Designer's autoconnect of slots change over to your own connects.

                  S Offline
                  S Offline
                  Shruthi
                  wrote on last edited by
                  #28
                  This post is deleted!
                  Christian EhrlicherC JonBJ 2 Replies Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #29

                    Again: your code does not even compile so how did you check it? What should your function do at all? And on_tableWidget_singleitemchanged() also crashes when there is at least one row.

                    Provide a fully, minimal compilable example!

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      Just one question - what should fillTableWidget() do at all (apart from the fact that it does not compile at all)? When rowCount() is greater than 0 then empty QTableWidgetItem's are set, nothing more.

                      Please provide a minimal, compilable example to reproduce your issue!

                      S Offline
                      S Offline
                      Shruthi
                      wrote on last edited by
                      #30

                      @Christian-Ehrlicher It will compile and it fills the tablewidget with values. But the signal is not triggering correctly when user typed some value to the tablewidget.
                      Please check only the signal and slot and let me know, if I have missed anything in that.
                      Thank you.

                      1 Reply Last reply
                      0
                      • S Shruthi

                        This post is deleted!

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #31

                        @Shruthi said in Regarding Signals and Slots:

                        s1 =->setTextAlignment(Qt::AlignCenter);

                        No, this does not compile!

                        it fills the tablewidget with values

                        No, it does not - you don't set a text to any of those QTableWidgetItems... provide compilable code!

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • S Shruthi

                          This post is deleted!

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #32

                          @Shruthi said in Regarding Signals and Slots:

                          void gen_window::on_tableWidget_singleitemchanged( )

                          You have made the slot a member of gen_window.

                          connect(ui->tableWidget,SIGNAL(itemChanged()),this,SLOT(on_tableWidget_singleitemchanged()));

                          You connect to it as a member of this, which is MainWindow.

                          Why do that I don't know. But if you used new signal & slot connection syntax, as I say to everyone, you would have known immediately. If you must use old style, check return result from connect()s and allow for runtime errors.

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #33

                            Hi
                            there is something wrong with slot and connect
                            its
                            void QTableWidget::itemChanged(QTableWidgetItem *item)

                            so connect is wrong as the parameter is not included
                            connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem *)),this,SLOT(on_tableWidget_singleitemchanged(QTableWidgetItem *)));
                            (using the new syntax is far better )

                            and your slot is also not on the spot

                            void gen_window::on_tableWidget_singleitemchanged( )
                            {
                            QTableWidgetItem *item; <<< this is bad as danglining pointer. item should be the parameter

                            so its
                            void gen_window::on_tableWidget_singleitemchanged(QTableWidgetItem *item )
                            {
                            QTableWidgetItem *item;

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Shruthi
                              wrote on last edited by Shruthi
                              #34

                              @mrjj @JonB @Christian-Ehrlicher @JoeCFD Thank you all for the replies.

                              1 Reply Last reply
                              0

                              • Login

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