PDA

View Full Version : QTableWidget and QCombobox



Stanfillirenfro
30th December 2013, 16:20
Hi to all!

I am facing a problem of retrieving all items from a given column of a QTableWidget to a QComboBox. The problem itself appears when I diplay the retrieved items in the ComboBox, because their number get increased. For instance, if I have three rows and four columns, three items are displayed repeately up to twelve in total. I just wanted to have three items corresponding to the number of the rows.

Some precisions:

1- Name is the name of the column fron wich the items should be selected.
2- m_details is my combobox.
3- m_tableau is my TableWidget.

Even the function:

m_details->setDuplicatesEnabled(false); does not solve the problem.

Could someone have a look on my peace of code and propose me an advice? I would be greatefull.

Here is my code:


for(int y = 0; y<m_tableau->rowCount(); y++)
{
for(int x = 0; x<m_tableau->columnCount(); x++)
{
valCol = m_tableau->horizontalHeaderItem(x);
valColConver = valCol->text();

if(valColConver == "Name")
{
valCell = m_tableau->item(y, x);

if(valCell != NULL)
{
valConver = valCell->text();

listeItem.push_back(valConver);

m_details->addItems(listeItem);

valConver.clear();
valColConver.clear();
}
}

}

Many thanks in advance.

anda_skoa
30th December 2013, 17:31
You call addItems in the inner loop, always with the same list instance. So every call to addItems add again all the previously added ones.

Just move the call to addItems to after the outer loop.

Cheers,
_

Stanfillirenfro
30th December 2013, 17:58
Dear Anda_skoa,

when I am reading your post, I just want to say YES!!!!!!!!!!!!!!!!!!!!!!!! and finaly I say it!!!

Many thnaks! It works perfectly!

Many many thanks!