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. QTableWidget ondatachange event disconnect

QTableWidget ondatachange event disconnect

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.7k 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.
  • A Offline
    A Offline
    avmg
    wrote on last edited by
    #1

    Hi,

    Actually i have a trouble that i can't solve and i couldn't found any solution at the moment...I have a QTablewidget with two columns that i want to fill with two different vectors. When i want to change the table's content with another different two vectors, first i call clearcontents() to set empty every cells, and after i fill the table with the new vectors.

    The problem is that if i clear the contents from the table, when i fill the table the program crashes and says "segmentation fault".

    After debug i saw that each time i fill one cell the program jump to the event on_datachanged, where i have a few instructions that can be the reason of the crash.

    So basically i don't know how to disconnect this event to avoid this problem. Anyway, maybe there's an easier way to clear and fill again a qtablewidget that at the end, is my simple objective.

    Any suggestion?

    Thanks,
    avmg.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      First there is the disconnect function to not call the slot, but that is a bit hard. When you only need to suppress the signals for a couple of instructions the @bool QObject::blockSignals(bool block)@ function (QObject derived function) may be used. Or implement the eventFilter and when the cell are filled, call the slot, if cells are empty, simply ignore the event.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • A Offline
        A Offline
        avmg
        wrote on last edited by
        #3

        Hi again,

        Nothing....I tried:

        blockSignals(true);
        ....
        ....
        ....
        blockSignals(false);

        Also:

        bool oldState = ui->table->blockSignals(true);
        ...
        ...
        ui->table->blockSignals(oldState);

        But the ondatachanged event still triggering. Also i'm not sure how to fill the cell content because even the instruction executes the value doesn't appear on the table. I tried:

        // Option 1:
        for(int i=0;i<10;i++)
        {
        ui->Table->item(i,0)->setData(Qt::DisplayRole, *(V+i));
        }

        // Option 2:
        for(int i=0;i<10;i++)
        {
        ui->Table->item(i,0)->setText(QString::number(*(V+i)));
        }

        // Option 3:
        for(int i=0;i<10;i++)
        {
        ui->Table->setItem(i,0,new QTableWidgetItem(V[i]));
        }

        V is a pointer to a double type vector. With this trigger signal and the filling table i'm getting a bit lost... I don't know why something as easy like clear and fill a table with double values is being so complicated for me...

        Thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You are blocking the signals from the view which is not what you want, it's the model that emits the signals you are after. BUT, you should rather fix your logic rather than work around the system.

          Option 3 corrected:

          @for(int i=0;i<10;i++)
          { ui->Table->setItem(i,0,new QTableWidgetItem(QString::number(V[i])));
          }@

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            If you want to fix the logic, the QEventFilter may be used. Or in the slot make sure the sells do have data items in it before executing the code!

            Greetz, Jeroen

            1 Reply Last reply
            0
            • A Offline
              A Offline
              avmg
              wrote on last edited by
              #6

              Solved!

              Finally my problem was the way i was filling the table, i changed it as SGaist said and it's working. Otherwise, can you show me and example of using the QEventFilter?

              Thanks!

              1 Reply Last reply
              0
              • JeroentjehomeJ Offline
                JeroentjehomeJ Offline
                Jeroentjehome
                wrote on last edited by
                #7

                Here is the doc
                "Events and Filters doc":http://qt-project.org/doc/qt-4.8/eventsandfilters.html

                Greetz, Jeroen

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  avmg
                  wrote on last edited by
                  #8

                  Thanks, this is very helpfull !

                  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