Why this code doesn't work?
I want to show the result of this query in the QLineEdit.
void testeMYSQL2::on_pushButton_clicked()
{
db.setHostName("localhost");
db.setDatabaseName("teste");
db.setUserName("root");
db.setPassword("");
db.open();
/* if (!db.open()){
QMessageBox::critical(0, tr("Error"),
QString("The error:\n%1").arg(db.lastError().text()));
}
else{
QMessageBox::information(0, tr("OK"), QString("The is NO error\n"));
}
*/
query.exec("select nome_prod from produtos where cod_prod = 1");
query.next();
for (int i = 0; i < record.count(); i++) {
QString name
= query.
value(i
).
toString();
nameEdit->setText(name);
}
void testeMYSQL2::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("teste");
db.setUserName("root");
db.setPassword("");
db.open();
/* if (!db.open()){
QMessageBox::critical(0, tr("Error"),
QString("The error:\n%1").arg(db.lastError().text()));
}
else{
QMessageBox::information(0, tr("OK"), QString("The is NO error\n"));
}
*/
QSqlQuery query;
query.exec("select nome_prod from produtos where cod_prod = 1");
query.next();
for (int i = 0; i < record.count(); i++) {
QString name = query.value(i).toString();
nameEdit->setText(name);
}
To copy to clipboard, switch view to plain text mode
What I am doing wrong?
Renan
Bookmarks