PDA

View Full Version : Blank rows after populating a QTableWidget



RenatoFerreira
20th November 2015, 22:31
Hi!

Sometimes I get blank rows at end of the QTableWidget after populating data. Look how it looks like:

11526

Just after sorting table (clicking over header) the blank rows simply disappear:

11527

What could be going on here? I double checked to confirm that I'm not setting wrong values with setRowCount(). Here is the code (https://github.com/renatoferreirarenatoferreira/quickmon/blob/master/Tools/snmptablewindow.cpp#L341).

Thanks!

ChrisW67
21st November 2015, 21:06
Dynamic sorting can get confused when adding new records (see note in QSortFilterProxyModel) Try disabling sorting while you add.

RenatoFerreira
22nd November 2015, 01:17
This is a QTableWidget, it is populated manually, not using models. I'm trying other things here, if I have any success I will post here.

ChrisW67
22nd November 2015, 07:16
QTableWidget is a QTableView that maintains a model internally for your convenience. The sorting functionality is inherited directly from QTableView and operates on the underlying model Did you actually try disabling sorting?

RenatoFerreira
22nd November 2015, 09:45
Well... It's an intermittent problem, I have to insist on table generation a few times in order to see it happening. I tried using the following:


ui->tableWidget->setSortingEnabled(false);

//add data

ui->tableWidget->setSortingEnabled(true);

I'm not sure if this method changes the dynamicSortFilter parameter in QSortFilterProxyModel. After a few tries the problem happened again, but now the application also crashes when I close the window after observing the blank rows. When I don't see the blank rows it closes without any issue.

I'm populating this table in two steps. In the first step I have the data to fill only one column, but I'm still creating all the empty QTableWidgetItems for the whole table. In the second step I'm only updating the remaining QTableWidgetItem with setText() or setData(). I'm disabling and enabling sorting before and after each step.

I'm suspecting that the problem is not with the data model, but while drawing the table graphics. I'm saying this because I cannot select the blank rows and after sorting they simply vanish.

Added after 4 minutes:

The only other weird thing I'm seeing in this QTableWidget happens when I call 'QTableWidget->setItem()' at the first time and then I receive the following errors in application output:

QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)

I don't how it could be related, maybe a coincidence, but I'm setting a QString:


QString nextSufix = nextVariable.OID.right(nextVariable.OID.size() - this->OIDs.first().size());

//add hidden column for index/sufix
ui->tableWidget->setItem(row, 0, new QTableWidgetItem(nextSufix));