I have a small program where I add delete and look for elements in a listView, but now I would like to add a couple of buttons to save and load the listView in a text format or any other, so I can use it in later sessions even though I find various problems looking for possible solutions on the web, I'm still a novice, this is my code:
-
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStringListModel>
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->listView->setModel(new QStringListModel(stringList));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_addButton_released()
{
if (ui->lineEdit->text().isEmpty()|| stringList.contains(ui->lineEdit->text())) {
QMessageBox::information(this, tr("Empty Field"),
tr("Por favor, introduce un nuevo codigo o el codigo ya existe."));
return;
}else{
stringList.append(ui->lineEdit->text());
((QStringListModel*) ui->listView->model())->setStringList(stringList);
ui->lineEdit->clear();
}
}
void MainWindow::on_removeButton_released()
{
if (ui->lineEdit->text().isEmpty() || !stringList.contains(ui->lineEdit->text())) {
QMessageBox::information(this, tr("Empty Field"),
tr("El codigo ha sido ya borrado o no existe."));
return;
}else{
stringList.removeOne(ui->lineEdit->text());
((QStringListModel*) ui->listView->model())->setStringList(stringList);
ui->lineEdit->clear();
}
}
void MainWindow::on_findButton_released()
{
if (ui->lineEdit->text().isEmpty()|| !stringList.contains(ui->lineEdit->text())) {
QMessageBox::information(this, tr("Empty Field"),
tr("CODIGO NO ENCONTRADO"));
return;
}else{
QMessageBox::information(this, tr("Empty Field"),
tr("CODIDO ENCONTRADO!"));
}
}
void MainWindow::on_saveButton_released()
{
}
void MainWindow::on_loadButton_released()
{
}
Someone has an idea where to go