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

Regarding Signals and Slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
34 Posts 6 Posters 3.9k 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by
    #9

    void QTableWidget::cellChanged(int row, int column)

    This signal is emitted whenever the data of the item in the cell specified by row and column has changed.

    S 1 Reply Last reply
    1
    • JoeCFDJ JoeCFD

      void QTableWidget::cellChanged(int row, int column)

      This signal is emitted whenever the data of the item in the cell specified by row and column has changed.

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

      @JoeCFD Thank you. I will try this.

      1 Reply Last reply
      0
      • mrjjM mrjj

        @Shruthi
        hi
        so ONE value from ONE cell must be copied to all other cells ?

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

        @mrjj yes correct.

        mrjjM 1 Reply Last reply
        0
        • S Shruthi

          @mrjj yes correct.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #12

          @Shruthi

          Ok. o.O

          void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item)
          {
              int numCols = ui->tableWidget->columnCount();
              int numRows = ui->tableWidget->rowCount();
              auto newValue = item->text();
              for (int row = 0; row < numRows; ++row) {
                  for (int col = 0; col < numCols ; ++col) {
                      auto cellItem = ui->tableWidget->item(row, col);
                      if (cellItem) cellItem->setText(newValue);
                  }
              }
          }
          

          alt text

          S 1 Reply Last reply
          8
          • mrjjM mrjj

            @Shruthi

            Ok. o.O

            void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item)
            {
                int numCols = ui->tableWidget->columnCount();
                int numRows = ui->tableWidget->rowCount();
                auto newValue = item->text();
                for (int row = 0; row < numRows; ++row) {
                    for (int col = 0; col < numCols ; ++col) {
                        auto cellItem = ui->tableWidget->item(row, col);
                        if (cellItem) cellItem->setText(newValue);
                    }
                }
            }
            

            alt text

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

            @mrjj Thank you so much. I will try this.

            mrjjM 1 Reply Last reply
            0
            • S Shruthi

              @mrjj Thank you so much. I will try this.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #14

              @Shruthi
              Np. Even its a bit odd :)

              make sure you use the itemChanged signal so it first happens when user press
              enter.

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

                @mrjj Sure I will be using itemChanged signal only. Thanks again :)

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

                  @mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?

                  mrjjM 1 Reply Last reply
                  0
                  • S Shruthi

                    @mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    @Shruthi
                    HI
                    I think the signal will also trigger when you fill the table.

                    To avoid that.
                    Either fill the table BEFORE you connect the signal.

                    or block its signals while filling it
                    https://doc.qt.io/qt-5/qsignalblocker.html

                    S 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Shruthi
                      HI
                      I think the signal will also trigger when you fill the table.

                      To avoid that.
                      Either fill the table BEFORE you connect the signal.

                      or block its signals while filling it
                      https://doc.qt.io/qt-5/qsignalblocker.html

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

                      @mrjj sure I will refer the link. Thank you.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Shruthi
                        wrote on last edited by
                        #19
                        This post is deleted!
                        JonBJ 1 Reply Last reply
                        0
                        • S Shruthi

                          This post is deleted!

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #20

                          @Shruthi
                          Your calls to blockSignals(false); and >blockSignals(true) are the wrong way round. You are supposed to block the signals for the duration of your changes. You also don't want to leave signals blocked when your slot exits!

                          1 Reply Last reply
                          1
                          • 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 Online
                                JonBJ Online
                                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 Online
                                      JonBJ Online
                                      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 Online
                                        Christian EhrlicherC Online
                                        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

                                          • Login

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