Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. is It possible to know how the signal QStandardItemModel::itemChanged is triggered?
Qt 6.12 LTS is out! See what's new in the release blog

is It possible to know how the signal QStandardItemModel::itemChanged is triggered?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.6k Views
  • 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.
  • L Offline
    L Offline
    Lee908
    wrote on last edited by
    #1

    Hi,

    Thers is a QStandardItemModel associated with a QTableView in my case, and the signal QStandardItemModel::itemChanged can be triggered in 2 different ways:

    1. Triggered by UI: User edits text of item from UI
    2. Triggered by coding: Call item->setText() by coding directly, skipping UI.

    How can I tell which is the true trigger? OR is there any other signal meeting that requirement? Any suggestion is appreciated. Thanks in advance.

    Christian EhrlicherC 1 Reply Last reply
    0
    • L Lee908

      Hi,

      Thers is a QStandardItemModel associated with a QTableView in my case, and the signal QStandardItemModel::itemChanged can be triggered in 2 different ways:

      1. Triggered by UI: User edits text of item from UI
      2. Triggered by coding: Call item->setText() by coding directly, skipping UI.

      How can I tell which is the true trigger? OR is there any other signal meeting that requirement? Any suggestion is appreciated. Thanks in advance.

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

      @Lee908 said in is It possible to know how the signal QStandardItemModel::itemChanged is triggered?:

      How can I tell which is the true trigger?

      You can't since the model does not know it since QSIM::setData() is called without a hint from where the modifcation came from (which would be pointless somehow - an enum with all possible entry methods? Why?)

      But since you call QStandardItem::setText() you know when the text is set programatically.

      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
      2
      • L Offline
        L Offline
        Lee908
        wrote on last edited by
        #3

        @Christian-Ehrlicher ,

        Thanks for your kindly suggestion.

        Actually, the reason I want to know the source of modification is :
        There are 2 table views A and B in my case. When user edit Table A via UI, setting a check box checked, QStandardItemModel::itemChanged would be emitted and inform of Table B to add a corresponding row. It works as expected. BUT when opening a file to read data, Table A and Table B are loaded respectively and I find there are many duplicated rows in Table B. The root cause is that when loading Table A, signal QStandardItemModel::itemChanged is also triggered.

        So I want to prevent that signal to add rows into Table B when load files. How can I use QStandardItem::setText() to solve this issue?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Lee908
          wrote on last edited by
          #4

          Figure out a way to solve my problem: block signal before loading data and release it after loading work is done.

          JonBJ 1 Reply Last reply
          1
          • L Lee908

            Figure out a way to solve my problem: block signal before loading data and release it after loading work is done.

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

            @Lee908
            Just so you are aware there is an alternative. Personally I regard Qt's blockSignals() as devil-spawn, because it blocks all signals and fails to mention what the consequences of that may be to correct operation when you only really wish to block a single signal.

            You could set a variable for the duration of "loading" and release at the end instead. That variable could be tested in the slot(s) for itemChanged() only and do nothing while set. Just a thought.

            L 1 Reply Last reply
            1
            • JonBJ JonB

              @Lee908
              Just so you are aware there is an alternative. Personally I regard Qt's blockSignals() as devil-spawn, because it blocks all signals and fails to mention what the consequences of that may be to correct operation when you only really wish to block a single signal.

              You could set a variable for the duration of "loading" and release at the end instead. That variable could be tested in the slot(s) for itemChanged() only and do nothing while set. Just a thought.

              L Offline
              L Offline
              Lee908
              wrote on last edited by
              #6

              @JonB
              Good suggestion. I can't agree more.

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