S
S
Slavka2015-12-28 12:40:26
Qt
Slavka, 2015-12-28 12:40:26

Qt, ListWidget update?

ui->ListDevice->clear();
        int k = 1;
        for(QVector< CDevice >::iterator it = arrDevice.begin(); it != arrDevice.end(); it++){
            QListWidgetItem *itemDevice = new QListWidgetItem;
            itemDevice->setText(it->getName());
            ui->ListDevice->insertItem(k,itemDevice);
            k++;
        }

Here is the code by which I want to update the ListWidget (ListDevice), and I get an out-of-range error, if I remove the cleanup, then everything works fine, but the list simply increases and is not replaced, what is the error here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2015-12-28
@tsarevfs

You are trying to add a 1-position element to an empty list (indexed from 0). int k = 0; It will most likely fix the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question