OOP in QML, trying to insert data in MySQL with an object
Hi, I'm new in the forum and I'm really bored trying to create an object to insert customers in a MySQL database.
I made a C++ class called gestionclientes (customer management) to make costumers objects. I made a void method called insertarCliente to insert the customers in the database. This is the code:
Code:
#include "gestionclientes.h"
/* INCLUDED */
#include <QtSql/QMYSQLDriver>
#include "string.h"
#include "iostream"
#include <QtSql/QSqlDatabase>
#include <QtDebug>
#include <QString>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
gestionClientes::gestionClientes()
{
}
db.setHostName("localhost");
db.setDatabaseName("miniaplicacion");
db.setUserName("root");
db.setPassword("medina");
bool ok = db.open();
if(ok == true){
query.prepare("INSERT INTO clientes (nombre_cliente,apellido_cliente,localidad_cliente) VALUES ( :nom, :ape, :local)");
query.bindValue(":nom",n);
query.bindValue(":ape",a);
query.bindValue(":local",p);
query.exec();
}else{
qDebug() << db.lastError();
qFatal( "Failed to connect." );
}
}
Sorry if my code is a shit, I'm a newbie and I want to learn :( . I need to dominate the creation of classes in QML to develop comfortable and more easy my Qt applications.
I need to create an object in the main QML file to insert new customers.
I program with Qt Creator.
Re: OOP in QML, trying to insert data in MySQL with an object
Hello KDEuser, welcome to QtCentre
Is there a problem you would like help with?
1 Attachment(s)
Re: OOP in QML, trying to insert data in MySQL with an object
Yes, I want to create a customer object in the QML file to insert new customers.
This is my Qt Creator project with the MySQL, sorry for the words written in Spanish.