I need help creating a function for deleting items from a QListWidget. I need to copy the name of the last item in the list, remove settings from .ini then remove from from QListWidget. So far all I can find is to how to use QList to delete the selected item.
My add function looks like:
void Edge::on_slotNew_pressed()
{
int i = ui->slotList->count();
i++;
QString slotNumber = "Slot" + QString::number(i);
ui->slotList->addItem(slotNumber);
QSettings settings("config.ini",QSettings::IniFormat);
qDebug() << settings.fileName();
settings.beginGroup(slotNumber);
settings.setValue("slotSizeW", m_prefs.slotSizeW);
settings.setValue("slotSizeH", m_prefs.slotSizeH);
settings.setValue("slotPosX", m_prefs.slotPosX);
settings.setValue("slotPosY", m_prefs.slotPosY);
settings.setValue("slotMax", m_prefs.slotMax);
settings.setValue("slotPriority", m_prefs.slotPriority);
settings.setValue("slotBorderless", m_prefs.slotBorderless);
settings.setValue("slotHotkey", m_prefs.slotHotkey);
settings.endGroup();
qDebug() << slotNumber;
}
**EDIT:**Updated Remove function
Currently my remove function looks like
void Edge::on_slotDelete_clicked()
{
QSettings settings("slots.ini",QSettings::IniFormat);
int i = ui->slotList->count();
QString slotNumber = "Slot" + QString::number(i);
QList<QListWidgetItem*> items = ui->slotList->selectedItems();
foreach(QListWidgetItem* item, items)
{
ui->slotList->removeItemWidget(item);
delete item;
}
settings.beginGroup(slotNumber);
settings.remove("");
settings.endGroup();
qDebug() << settings.fileName();
}
I derped and forgot to update the config name so removal works, I just possibly need a better naming convention as it has to be passed as a QString, QListWidgetItem* will not pass correctly