I've been doing a code where a database is manipulated, elements are saved and edited by a Qsqlite database and query, so the way I've used is to pass query by parameter I don't know how bad it is but every time it goes By parameter I get this warning: " QSqlQuery is deprecated: is not mean to be copied: use move construction instead" and I wanted to know the correct way to do it, I show the MainWindow constructor, (the warning is indicated in the main).
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
char dirNow[1024];
db = QSqlDatabase::addDatabase("QSQLITE");
QString dirfull = QString(_getcwd(dirNow, 1024)) + "\\inventario.db";
db.setDatabaseName(dirfull);
if(!db.open()){
qDebug() << db.lastError().text();
}
model = new QSqlQueryModel();
QSqlQuery query(db);
if(!query.exec("CREATE TABLE IF NOT EXISTS articulo (codigo INTEGER NOT NULL, nombre VARCHAR(55) NOT NULL, unidades INTEGER NOT NULL, "
"categoria VARCHAR(55) NOT NULL, pais VARCHAR(55) NOT NULL, precio DOUBLE NOT NULL, foto VARCHAR(200) NOT NULL, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT) ")){
QMessageBox::information(this, "Error", query.lastError().text());
}
if(!query.exec("CREATE TABLE IF NOT EXISTS categorias(valor VARCHAR(55) NOT NULL) ")){
QMessageBox::information(this, "Error", query.lastError().text());
}
//query.prepare("DELETE FROM articulo WHERE = 1");
//query.addBindValue("");
"Warning is here: " id = imprimirArticulos(query);
"Warning is here: " QObject::connect(ui->registrarBtn, &QPushButton::clicked, this, [=]()->void{registrarArticulo(query); });
QObject::connect(ui->addImagenBtn, &QPushButton::clicked, this, [=]()->void{subirFoto();});
"Warning is here: " QObject::connect(ui->buscarBtn, &QPushButton::clicked, this, [=]()->void{filtroArticulos(query);});
"Warning is here: " imprimirCategorias(query);
"Warning is here: " QObject::connect(ui->categoriasCBox, &QComboBox::currentIndexChanged, this, [=]()->void{agregarCategorias(query);});
model->setQuery(std::move(query));
}