通过一个字段查询数据库表,并将所有结果显示在tableWidget中,这怎么实现啊,求一段代码
------解决方案--------------------
查询一个字段:
QSqlQuery query;
query.prepare("select * from 表名 where 列名=:dname");
QString str = QString("%1").arg(所查询的变量名);
query.bindValue(":dname",str);
query.exec();
将所有结果显示在tableWidget:
while(query.next())
{
QLabel *label = new QLabel();
label->setText(query.value(0).toString());
ui->tableWidget->setCellWidget(1,0,label);
}
大致差不多这么写,凑合着用吧,自己再改改咯。