Jūs esate

Problem with QTableWidgetItem and QTableWidget

I have a small problem with QTableWidget and QTableWidgetItem. I have a QHash<QString, QString> downloadQueue. There is at least one entry inside downloadQueue. The point is, that items inside downloadQueue are not added to the QTableWidget. I don't know  why.
void MDIChildWindow::regenerateTabs() {

m_ui->tableWidgetDownloadQueue->clearContents();

int row = 0;

// Added line

m_ui->tableWidgetDownloadQueue->setRowCount(this->favoritiesItems.count());

// End of added

foreach(QString key, downloadQueue.keys()) {

QTableWidgetItem *download = new QTableWidgetItem(key);

download->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

m_ui->tableWidgetDownloadQueue->setItem(row, 0, download);

QTableWidgetItem *location = new QTableWidgetItem(downloadQueue.value(key) + "/" + key);

location->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

m_ui->tableWidgetDownloadQueue->setItem(row++, 1, location);

}

}

Inside foreach() key and downloadQueue.value(key) returns valid values (QStrings).

Do you have any ideas why this is not working???

--------Edited----------------

I found a solution. The problem is, that you need to add a number of entries:

m_ui->tableWidgetDownloadQueue->setRowCount(this->favoritiesItems.count());

Komentuoti