QML与C++交互:在qml中使用QSqlQueryModel显示数据库数据
參考链接:
环境:
主机:WIN7
开发环境:Qt5.2.1
说明:
在QML中不能直接对数据库进行操作,所以将QSqlQueryModel封装成子类,作为属性给QML使用
效果图:
源码:
qml文件里负责数据托管显示的代码:
Component
{
id: msnDelegate
Item
{
id: wrapper
width: grid.cellWidth; height: grid.cellHeight
Column
{
Image{ source: "pics/light_on.png";anchors.horizontalCenter: parent.horizontalCenter; width: grid.cellWidth * 0.7; height: grid.cellHeight * 0.7}
Text { text: ctrl_id;anchors.horizontalCenter: parent.horizontalCenter; color: wrapper.GridView.isCurrentItem ?
"red" :"blue" }
Text { text: na