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 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
    • mrjjM mrjj

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

      mrjjM 1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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
        4
        • mrjjM mrjj

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

          mrjjM 1 Reply Last reply
          1
          • K Kris Revi

            @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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            1
            • mrjjM mrjj

              @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 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?!

              JonBJ 1 Reply Last reply
              0
              • K Kris Revi

                @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?!

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #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
                2
                • JonBJ JonB

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

                    • Login

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