目录
效果展示:
登录界面:
主界面:
主界面:
修改用户,新建用户界面:
登录界面QMl代码:
// 输入框代码段
ColumnLayout {
x: 170
y: 192
width: 300
height: 125
Rectangle{
id:rect_Id
Layout.preferredHeight: 50
Layout.preferredWidth: 300
Image {
id: imageId
x: 10
y: 9
width: 30
height: 30
source: "qrc:/res/id.png"
fillMode: Image.PreserveAspectFit
}
TextField {
id: textField_Id
x: 50
y: 5
width: 241
height: 40
text: qsTr("")
verticalAlignment: Text.AlignVCenter
font.pixelSize: 12
font.family: "微软雅黑"
color: "black" //"#B2B2B2"
cursorVisible: true;
selectByMouse: true //是否可以选择文本
selectionColor: "#999999"//选中背景颜色
placeholderText: qsTr("请输入账号")
focus: true;
background: Rectangle {
border.width: 0; //border.color: "#B2B2B2"
radius: 5;
color: "#000000" //"transparent"
opacity: 0.05
implicitHeight: 40;
implicitWidth: 280
}
}
}
Rectangle{
id:rect_Pwd
Layout.preferredHeight: 50
Layout.preferredWidth: 300
Image {
id: imagePwd
x: 10
y: 9
width: 30
height: 30
source: "qrc:/res/pwd.png"
fillMode: Image.PreserveAspectFit
}
TextField {
id: textField_Pwd
x: 50
y: 5
width: 240
height: 40
text: qsTr("")
verticalAlignment: Text.AlignVCenter
font.pixelSize: 12
font.family: "微软雅黑"
color: "black" //"#B2B2B2"
cursorVisible: true;
selectByMouse: true //是否可以选择文本
selectionColor: "#999999"//选中背景颜色
placeholderText: qsTr("请输入密码")
background: Rectangle {
border.width: 0; //border.color: "#B2B2B2"
radius: 5;
color: "#000000" //"transparent"
opacity: 0.05
implicitHeight: 40;
implicitWidth: 280
}
}
}
}
CPP中获取表中所有学生信息数据代码:
//CPP中获取表中所有学生信息数据代码段
QSqlQuery query;
QList< QMap<QString, QVariant> > tempList;
QList<QString> fieldList; //存放所有字段的List
QString str="select * from student_db.StudentInfo";
if(query.exec(str))
{
QSqlRecord record = query.record();
int cloumnCount = record.count(); //返回字段列数
for(int i=0; i<cloumnCount; ++i)
{
fieldList.append(record.fieldName(i));
//qDebug()<<fieldList.at(i);
}
while(query.next())
{
QMap<QString, QVariant> tempMap;
for(int i=0; i<cloumnCount; i++)
{
tempMap.insert(fieldList.at(i), query.value(fieldList.at(i)));
}
tempList.append(tempMap);
}
qDebug()<<"执行成功!!!";
}
Qt5.9开发,以QML和C++混合编程来开发的;Qml作为界面处理,数据的逻辑处理在cpp端完成;
具体有登录界面 、主界面;功能包括删除全部学生,删除单个学生,添加学生,修改学生,查询学生(支持模糊查询),全部源码私信即可。