Hi. I have made a simple testing program which I'll use in another program later. I create the items of the QListWidget through looping and now I want to make changes in one of the items of the list, which the user clicks. But when I call a fucntion to edit the item, i recieve errors. How can i edit an item of the QListWidget?
Here is the code:
#include "itemdialog.h"
#include "ui_itemdialog.h"
#include <QDebug>
#include <QListWidget>
#include <QListWidgetItem>
ItemDialog::ItemDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ItemDialog)
{
ui->setupUi(this);
item=new QListWidget(this);
for(int i=0;i<10;i++)
{
QListWidgetItem *itm= new QListWidgetItem;
itm->setText(QString::number(i));
item->addItem(itm);
connect(item,SIGNAL(clicked(QModelIndex)),this,SLOT(dis(QModelIndex)));
}
}
void ItemDialog::dis(QModelIndex a)
{
item->itemFromIndex(&a)->setBackgroundColor(Qt::red); // [B]HERE IS THE ERROR[/B]
}
ItemDialog::~ItemDialog()
{
delete ui;
}