Appcrash after sql statement with QString
-
Hello,
If i execute this sql-statement my app crashes if I change a ComboBox item
@
void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
{if(!db.isOpen()) { qDebug() << "DB is not open!"; } QSqlQuery q; q.exec("SELECT * FROM autos WHERE snr = '"+ arg1 +"'"); }
@
If i use this it works...
@
void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
{if(!db.isOpen()) { qDebug() << "DB is not open!"; } QSqlQuery q; q.exec("SELECT * FROM autos WHERE snr = '0588/835'"); }
@
why....???? :/
-
Hi,
what's the content of arg1?
@
qDebug() << arg1;
@ -
@
"0588/835"
@ -
Try to bind the value for snr:
@
QSqlQuery q;
q.prepare("SELECT * FROM autos WHERE snr = :sachnr");
q.bindValue(":sachnr", arg1);
if (!q.exec()) {
qDebug() << q.lastError().text()
return;
} else {
//...
}
@ -
I don´t know why, but now both solutions are working...
thanks anyway