qt中sqlite数据库查询使用变量问题
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("select id,math,MCU,ARM,GUI from student where name = '刘明'");
这样可以用,我想用变量形式
变成这样
QString names = '刘明';
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("select id,math,MCU,ARM,GUI from student where name = names");
这样就不行了!求各位大侠帮帮忙干怎么办!!!非常感谢了!
[解决办法]
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("select id,math,MCU,ARM,GUI from student where name = '刘明'");
这样可以用,我想用变量形式
变成这样
QString names = '刘明';
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery(QString("select id,math,MCU,ARM,GUI from student where name = '%1'").arg(names));