一个月前接触到了Qml,也做过一些练习,但只能实现动画和简单的布局功能,逻辑部分和数据处理很难上手,看到许多人将C++和结合起来,Qml负责界面设计,C++实现逻辑处理,但将C++注册到 Qml中一直让我头疼,比如属性声明和函数声明类想不通为什么这么做,可能是时间问题吧,慢慢的就发现了其实也不难,花了好几天做成了这个小应用,算是这一阶段的小小纪念吧。

下来就是贴代码的时间了.

先是main.qml

启动时先进入登录界面

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.0
import Login_gui 1.0
import QtQuick.Particles 2.0 Window {
visible: true
id:mainwindow
width: 300
height: 533
color: "#F0F0F0"
LoginDialog {}
}

LoginDialog的代码如下

import QtQuick 2.0
import Login_gui 1.0
import QtQuick.Controls 1.1
Rectangle {
id:loginsence
width: 300
height: 533
color: "#F0F0F0"
visible: true
x:300
Component.onCompleted: {
x=0;
}
Behavior on x {
NumberAnimation {easing.type:Easing.OutQuint;duration: 1100}//OutQuint动画效果 结束时速度变慢
} property string userselect
/*************************************************************************************/
//登陆请求函数
function login_req()
{
//判断用户名是否有效
if (userinput.text== "")
{
message.text = "请输入用户名!"
message.opacity = 1
return
}
//判断密码是否有效
if (passwordinput.text == "")
{
message.text = "请输入密码!"
message.opacity = 1
return
}
//显示登陆动画
load_gif.opacity = 1
//登陆请求
//console.log("***********************")
login_gui.user_id = userinput.text
login_gui.password = passwordinput.text
login_gui.slot_login_req()
} /*************************************************************************************/
Login_gui{
id:login_gui
property var loginstudent
onSig_login_result:
{
//关闭登陆动画
load_gif.opacity = 0
//根据登陆结果处理
switch (result)
{
//登陆成功
case 0:
message.text = "登陆成功"
message.opacity = 1
if(userselect=="studentselect " )
{ loginstudent= Qt.createComponent("StudentDialog.qml").createObject(loginsence);break; }
else
{ loginstudent= Qt.createComponent("TeacherDialog.qml").createObject(loginsence);break; }
//无此用户名
case 1:
message.text = "登陆失败:无此用户名"
message.opacity = 1
break;
//密码错误
case 2:
message.text = "登陆失败:密码错误"
message.opacity = 1
break;
case 3:
message.text = "登陆失败:请选择登录类型"
message.opacity = 1
}
}
}
/************************************************************************/
Rectangle //顶栏
{
id: top_bar
anchors.left: parent.left;
anchors.leftMargin: parent.width/2;
anchors.top: parent.top;
anchors.topMargin: 10;
border.color: "#707070"
Text
{
id: title
anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
text: "登陆"
font.bold: true
font.pixelSize: mainwindow.height/25;
color: "blue"
}
}
/**************************************************************/
//用户名框
Rectangle{
id:loginBox
height:parent.height/16;width:parent.width;
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.top: parent.top;
anchors.topMargin: 150;
color:"white"
Row{
spacing:1
Rectangle//用户名框
{ id:user
height:loginBox.height;width:loginBox.width/4;
anchors.left: loginBox.left;
anchors.leftMargin:0;
anchors.bottom: loginBox.bottom;
anchors.bottomMargin: 0;
Text{
text: "用户名:";
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 0;
font.bold:false
font.family: "微软雅黑"
color:"black"
font.pointSize: 15
}
}
Rectangle//用户名输入框
{
id:loginuser
height:loginBox.height;width:loginBox.width-user.width;
anchors.left: loginBox.left;
anchors.leftMargin:user.width;
anchors.bottom: loginBox.bottom;
anchors.bottomMargin: 0;
TextInput
{ id:userinput
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 0;
width: parent.width
height: parent.height/2
font.family: "微软雅黑"
font.pointSize: 15
focus: true
color:"black"
text: "王红"
// MouseArea { anchors.fill: user;onClicked: user.selectAll()}
}
}
}
}
/************************************************************************/
//密码框
Rectangle{
id:passwordBox
height:parent.height/16;width:parent.width;
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.top: parent.top;
anchors.topMargin: loginBox.height+151;
color:"white"
Row{
spacing: 1
Rectangle//密码框
{ id:password
height:passwordBox.height;width:passwordBox.width/4;
anchors.left: passwordBox.left;
anchors.leftMargin:0;
anchors.bottom: passwordBox.bottom;
anchors.bottomMargin: 0;
Text{
text: "密 码:";
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 0;
font.family: "微软雅黑"
font.pointSize: 15
}
}
Rectangle{ //密码输入框
id:loginpassword
height:passwordBox.height;width:passwordBox.width-password.width;
anchors.left: passwordBox.left;
anchors.leftMargin:password.width;
anchors.bottom: passwordBox.bottom;
anchors.bottomMargin: 0;
color:"white"
TextInput{
id:passwordinput
text: "1234567"
anchors.left: parent.left;
anchors.leftMargin:0;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 0;
width: parent.width
height: parent.height/2
font.family: "微软雅黑"
font.pointSize: 15
// MouseArea { anchors.fill: password;onClicked: password.selectAll()} }
}
}
}
/************************************登录*******************************************/
Rectangle{
id: loginbutton
anchors.left: parent.left
anchors.leftMargin: 6
anchors.top: passwordBox.top
anchors.topMargin: parent.width/4.2;
width: parent.width-12;
height: passwordBox.height;
radius: 5 //倒角
color:"#19cff7"
Text{
anchors.horizontalCenter: parent.horizontalCenter //水平中心
anchors.verticalCenter:parent.verticalCenter //垂直中心
text:"登录"
font.family: "华文细黑"
styleColor: "white"
font.pointSize: 15
}
MouseArea {
anchors.fill: parent;
onClicked:{console.log(passwordinput.text); login_req()} }
}
/************************************登录动画*****************************************/
AnimatedImage
{
id: load_gif ;
source: "qrc:/new/prefix1/image/login.gif"
anchors {horizontalCenter: mainwindow.horizontalCenter;verticalCenter:mainwindow.verticalCenter}
y: 180; x:90
opacity: 0
} /***************************************信息框*************************************/
Rectangle{
anchors.horizontalCenter: parent.horizontalCenter //水平中心
anchors.bottom: loginBox.bottom
anchors.bottomMargin:45;
width: loginbutton.width/2;
height: loginbutton.height/2;
radius: 3 //倒角
color: "#F0F0F0"
Text{
id:message
anchors.horizontalCenter: parent.horizontalCenter //水平中心
anchors.verticalCenter:parent.verticalCenter //垂直中心
font.family: "华文细黑"
styleColor: "black"
font.pointSize: 10
opacity: 0
} }
/****************************注册*************************************/
Rectangle{
id:newuserrer
anchors.right: parent.right;
anchors.rightMargin: 28;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 35;
Text
{
id: newuser
anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
text: "新用户"
font.family: "华文细黑"
font.pixelSize: 12 color: "#3aa7ea"
MouseArea {
anchors.fill: parent;
property var login
onClicked:
{
login= Qt.createComponent("NewUserDialog.qml").createObject(loginsence);
loginsence.deleteLater();
}
}
} }
/****************************登录类型*************************************/ Rectangle {
anchors.horizontalCenter: parent.horizontalCenter //水平中心
anchors.bottom:loginbutton.bottom;
anchors.bottomMargin: (loginbutton.y-passwordBox.y+loginbutton.height)/2
ExclusiveGroup {
id: language;
}
Row {
anchors.centerIn: parent;
spacing:loginsence.width/4.5
CheckBox {
id:student
text: "学生登录";
exclusiveGroup: language;
onCheckedChanged: { if(checked){login_gui.student=true;login_gui.teacher=false;userselect="studentselect " } }
} CheckBox {
id:teacher
text: "教师登录";
exclusiveGroup: language;
onCheckedChanged: { if(checked){ login_gui.teacher=true;login_gui.student=false;userselect="teacherselect"} }
}
}
} /************************************************************************************/
}

没什么难点,主要是界面布局费点事,定义了一个属性property string userselect来标标识是管理员登录还是学生登录,以便进图不同的界面。还有就是使用Textinput是,需要设置高度和宽度,否则无法输入文字,这个很是奇怪,我觉得软件做的不够人性化,好了,今天就先到这里了。

Qml和C++开发的学生信息管理软件一的更多相关文章

  1. 企业信息管理软件 OA、CRM、PM、HR 财务、ERP等

    本文就企业信息管理软件做一个记录. 最近公司要开发物料管理系统....于是查找一些资料 Excel垄断企业信息管理软件二三十年无人撼动:OA.CRM.PM.HR软件不温不火难以普及. 已有的信息化市场 ...

  2. 【学员管理系统】0x02 学生信息管理功能

    [学员管理系统]0x02 学生信息管理功能 写在前面 项目详细需求参见:Django项目之[学员管理系统] Django框架大致处理流程 捋一下Django框架相关的内容: 浏览器输入URL到页面展示 ...

  3. 一起来开发Android的天气软件(三)——使用Volley实现网络通信

    距离上一篇一起来开发Android天气软件二的时间又将近半个月了,之间一直由于有事而没有更新实在抱歉,近期会加快更新的步伐.争取在2015年到来前写完这系列的博文,上一章我们已经使用LitePal框架 ...

  4. 个人整理的 Windows 下 .NET 开发必装的软件

    注: 最后更新时间:2019-03-15 一..NET 开发 1. 必装 软件名称 说明 下载地址 JetBrains Toolbox JetBrins 全家桶管理工具. 下载地址 JetBrains ...

  5. 术语-软件-软件开发:SDK(软件开发工具包)

    ylbtech-术语-软件-软件开发:SDK(软件开发工具包) 软件开发工具包(缩写:SDK.外语全称:Software Development Kit)一般都是一些软件工程师为特定的软件包.软件框架 ...

  6. c#开发地磅称重软件

    2012年时即做过一个地磅称重软件,最近公司又接了一个地磅过磅软件的项目,把遇到的问题总结一下以备后用. 1.接线问题 因为客户方原来单独使用仪表,仪表未有接线和电脑连接,为此颇费周折才做好了接线.接 ...

  7. window下的开发环境:常用软件

    window下的开发环境:常用软件 Visio 2010  - 产品设计 xmind        -产品设计 Axure       -产品设计 Edraw max 7.3(破解版)  -产品设计 ...

  8. python开发的学生管理系统

    python开发的学生管理系统(基础版) #定义一个函数,显示可以使用的功能列表给用户 def showInfo(): print("-"*30) print(" 学生管 ...

  9. "零代码”开发B/S企业管理软件之一 :怎么创建数据库表

    声明:该软件为本人原创作品,多年来一直在使用该软件做项目,软件本身也一直在改善,在增加新的功能.但一个人总是会有很多考虑不周全的地方,希望能找到做同类软件的同行一起探讨. 本人文笔不行,能把意思表达清 ...

随机推荐

  1. [openjudge-搜索]单词接龙

    题目描述 描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙&q ...

  2. 创建servlet程序知识点详解---servlet-day01

    方法调用完后,其中的所有局部变量都会消失 ###网络架构 -CS:Client Server  客户端服务器 特点:每种平台都需要开发相对应的app, 开发成本高  功能升级需要下载最新的客户端,用户 ...

  3. Node + Redis 实现分布式Session方案(转载)

    Session是什么? Session 是面向连接的状态信息,是对 Http 无状态协议的补充. Session 怎么工作? Session 数据保留在服务端,而为了标识具体 Session 信息指向 ...

  4. kubernetes1.5新特性(二):支持Photon卷插件

    在Kubernetes中卷的作用在于提供给POD持久化存储,这些持久化存储可以挂载到POD中的容器上,进而给容器提供持久化存储. 从图中可以看到结构体PodSpec有个属性是Volumes,通过这个V ...

  5. window 系统虚拟机安装mac系统

    前言: 我们用的是虚拟机,物理机安装一是复杂,二是兼容性实在太差,所以不推荐使用,除非你的电脑配置不够.这篇文章很长,如果想安装的话建议收藏,否则你有可能记不住步骤,我尽量缩减步骤,所以如果你想安装黑 ...

  6. HTML5的自定义属性的使用总结

    https://blog.csdn.net/qq_31851435/article/details/53100691 <div id="myDiv" data-attribu ...

  7. WebApi返回的Json去掉XML

    在global.asax.cs文件中的 application_start()方法中加入下面一句话 GlobalConfiguration.Configuration.Formatters.XmlFo ...

  8. BZOJ 4480 [JSOI2013] 快乐的jyy

    思路 两个字符串都插入回文自动机中(每次重置last) 最后统计两个right集合的大小就好了 代码 #include <cstdio> #include <algorithm> ...

  9. UnicodeMath数学公式编码_翻译(Unicode Nearly Plain - Text Encoding of Mathematics Version 3)

    目录 完整目录 1. 简介 2. 编码简单数学表达式 2.1 分数 2.2 上标和下标 2.3 空白(空格)字符使用 3. 编码其他数学表达式 3.1 分隔符 强烈推荐本文简明版UnicodeMath ...

  10. Linux 命令行下导入导出 .sql 文件

    一.导出数据库用的是 mysqldump 命令 1.导出数据和表结构 /usr/bin/mysqldump -u 用户名 -p 数据库名 > 数据库名.sql 敲回车键后会提示输入密码 注意 m ...