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. Stop a signal from firing from code!
Forum Updated to NodeBB v4.3 + New Features

Stop a signal from firing from code!

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 485 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on 7 Sept 2021, 12:38 last edited by
    #1

    this

    void MainWindow::on_tableWidgetDeviceList_cellChanged(int row, int column)
    {
    }
    

    gets fired when i populate the tableWidget within code! i ONLY want to fire this off when a USER changes a cell text! how?

    i googled and found this

    ui->tableWidgetDeviceList->blockSignals(true);
    

    but did not work

    1 Reply Last reply
    0
    • M mrjj
      7 Sept 2021, 12:47

      Hi

      Best way to fix this is not to use the auto connect feature.
      (GoOto Slot, and name on_tableWidgetDeviceList_cellChanged)

      and simply use manual connect staement.

      Then you first fill the table.
      then you connect the slots.

      No issues and better desgin. :)

      K Offline
      K Offline
      Kris Revi
      wrote on 7 Sept 2021, 13:06 last edited by
      #3

      @mrjj ty :) got it working like this

      void cellwasChanged(int row, int column);
      
      connect(ui->tableWidgetDeviceList, &QTableWidget::cellChanged, this, &MainWindow::cellwasChanged);
      
      void MainWindow::cellwasChanged(int row, int column)
      {
          qDebug() << "Row : " << row << "Column : " << column;
      }
      

      but why is it when using the auto goto slot -> cellChanged code triggers that slot but doing it manu it doe not :S

      M 1 Reply Last reply 8 Sept 2021, 04:53
      1
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 7 Sept 2021, 12:47 last edited by
        #2

        Hi

        Best way to fix this is not to use the auto connect feature.
        (GoOto Slot, and name on_tableWidgetDeviceList_cellChanged)

        and simply use manual connect staement.

        Then you first fill the table.
        then you connect the slots.

        No issues and better desgin. :)

        K 1 Reply Last reply 7 Sept 2021, 13:06
        4
        • M mrjj
          7 Sept 2021, 12:47

          Hi

          Best way to fix this is not to use the auto connect feature.
          (GoOto Slot, and name on_tableWidgetDeviceList_cellChanged)

          and simply use manual connect staement.

          Then you first fill the table.
          then you connect the slots.

          No issues and better desgin. :)

          K Offline
          K Offline
          Kris Revi
          wrote on 7 Sept 2021, 13:06 last edited by
          #3

          @mrjj ty :) got it working like this

          void cellwasChanged(int row, int column);
          
          connect(ui->tableWidgetDeviceList, &QTableWidget::cellChanged, this, &MainWindow::cellwasChanged);
          
          void MainWindow::cellwasChanged(int row, int column)
          {
              qDebug() << "Row : " << row << "Column : " << column;
          }
          

          but why is it when using the auto goto slot -> cellChanged code triggers that slot but doing it manu it doe not :S

          M 1 Reply Last reply 8 Sept 2021, 04:53
          1
          • K Kris Revi
            7 Sept 2021, 13:06

            @mrjj ty :) got it working like this

            void cellwasChanged(int row, int column);
            
            connect(ui->tableWidgetDeviceList, &QTableWidget::cellChanged, this, &MainWindow::cellwasChanged);
            
            void MainWindow::cellwasChanged(int row, int column)
            {
                qDebug() << "Row : " << row << "Column : " << column;
            }
            

            but why is it when using the auto goto slot -> cellChanged code triggers that slot but doing it manu it doe not :S

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 8 Sept 2021, 04:53 last edited by
            #4

            @Kris-Revi

            • but why is it when using the auto goto slot -> cellChanged code triggers that slot but doing it manu it doe not :S

            That is simply the order.
            Auto connected is run in setupUI() and you fill after

            with manual connect you fill first, then connect.

            So as non magical as it gets . :)

            K 1 Reply Last reply 8 Sept 2021, 10:07
            1
            • M mrjj
              8 Sept 2021, 04:53

              @Kris-Revi

              • but why is it when using the auto goto slot -> cellChanged code triggers that slot but doing it manu it doe not :S

              That is simply the order.
              Auto connected is run in setupUI() and you fill after

              with manual connect you fill first, then connect.

              So as non magical as it gets . :)

              K Offline
              K Offline
              Kris Revi
              wrote on 8 Sept 2021, 10:07 last edited by
              #5

              @mrjj befor i mark this as solved! is it better to do manual connect on everything from buttons, sliders and so on then the "auto goto slot" then?!

              J 1 Reply Last reply 8 Sept 2021, 10:25
              0
              • K Kris Revi
                8 Sept 2021, 10:07

                @mrjj befor i mark this as solved! is it better to do manual connect on everything from buttons, sliders and so on then the "auto goto slot" then?!

                J Offline
                J Offline
                JonB
                wrote on 8 Sept 2021, 10:25 last edited by JonB 9 Aug 2021, 10:26
                #6

                @Kris-Revi
                Yep! More powerful, less gotchas. That's just how it is. See how we are having a similar conversation at https://forum.qt.io/topic/128677/no-documents-matching-ui_form-h-could-be-found/9, with same recommendation though for specific gotcha-reason there.

                K 1 Reply Last reply 8 Sept 2021, 10:39
                2
                • J JonB
                  8 Sept 2021, 10:25

                  @Kris-Revi
                  Yep! More powerful, less gotchas. That's just how it is. See how we are having a similar conversation at https://forum.qt.io/topic/128677/no-documents-matching-ui_form-h-could-be-found/9, with same recommendation though for specific gotcha-reason there.

                  K Offline
                  K Offline
                  Kris Revi
                  wrote on 8 Sept 2021, 10:39 last edited by
                  #7

                  @JonB sweet :) i'll check it out! gonne remove all my auto goto slots and do them manualy :)

                  1 Reply Last reply
                  2
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on 8 Sept 2021, 10:48 last edited by
                    #8

                    For people ending up here from Google:
                    If you want a signal to be sent only when the user edits the cell and not when it's done by internal processes the correct way is a simple custom delegate:

                    class EditSignalDelegate : public QStyledItemDelegate {
                    Q_OBJECT
                    public:
                    using QStyledItemDelegate::QStyledItemDelegate ;
                    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override {
                    QStyledItemDelegate::setModelData(editor,model,index);
                    indexEdited(index);
                    }
                    signals:
                    void indexEdited(const QModelIndex &index);
                    };
                    

                    Now you can use

                    EditSignalDelegate* delegate = new EditSignalDelegate(this);
                    connect(delegate,&EditSignalDelegate::indexEdited,this,[](const QModelIndex &index){qDebug() << "cell edited " << index.row() << "," <<index.column();});
                    ui->tableWidgetDeviceList->setItemDelegate(delegate);
                    

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    3

                    1/8

                    7 Sept 2021, 12:38

                    • Login

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