QT知识(毕设需要)

1 新建ui界面:项目新增文件-》QT-》QT设计师界面类
2 联立切换相关:切换需要加载另一个界面的头文件,私有成员添加成员指针(可直接实例化)
槽函数实例化对象,设置,->show();隐藏父界面this->hide();字界面退出->exec();父界面show
3 获取带日期的时间,使用QDateTime类
QDateTime current_date_time =QDateTime::currentDateTime();
QString current_date =current_date_time.toString(“yyyy.MM.dd hh:mm:ss.zzz ddd”);
current_date字符串结果为"2016.05.20 12:17:01.445 周五",其中时间的显示格式可灵活配置,此处简单说明本实例中用到的部分:
yyyy表示年;MM表示月;dd表示日; hh表示小时;mm表示分;ss表示秒;zzz表示毫秒;ddd表示周几
详细配置格式内容较多,有需要的请自行查看Qt Assistant中关于函数QString QDateTime::toString ( const QString & format ) const的说明
4 只需要时间,不需要日期,也可使用QTime类
QTime current_time =QTime::currentTime();
int hour = current_time.hour();//当前的小时
int minute = current_time.minute();//当前的分
int second = current_time.second();//当前的秒
int msec = current_time.msec();//当前的毫秒
实现两个ui界面跳转
void MainWindow::on_pushButton_clicked()
{
m= new m1();
m->setModal(true);
m->resize(1400,900);
this->hide();
connect(m,SIGNAL(sendsignal()),this,SLOT(reshow()));
m->show();
// m->exec();
//if()
// this->show();
}
void MainWindow::reshow()
{
this->show();
m->close();
}
1、窗体标题:setWindowTitle(const QString &)。例:setWindowTitle(“窗口”);
2、固定窗口大小:setMaximumSize(const QSize &size)。 例:setMaximumSize(300,300);
setMinimumSize(const QSize &size)。 例:setMinimumSize(300, 300);
3、设置窗口在其父窗口的位置 :move(int x, int y) 例:move(100, 100);
4、设置背景色:setStyleSheet(const QString &styleSheet)。例:setStyleSheet(“background:red”);
5、窗口标志,窗口系统的零或多个提示的组合:setWindowFlags(Qt::WindowFlags type)
例:setWindowFlags(Qt::FramelessWindowHint); //生成无边框窗口。用户无法通过窗口系统移动或调整无边框窗口的大小
setWindowFlags(Qt::WindowCloseButtonHint); //去掉最大化最小化按钮,保留关闭按钮。

  6、设置背景图片(不推荐使用background-image,因为它不会随着窗口的大小变换而把图片全部印制在背景上):setStyleSheet("border-image:url(:/image/test.jpg)");

  7、设置透明背景:setAttribute(Qt::WA_TranslucentBackground, true);

数据库
创建一个数据库
格式为:create database 数据库名;
例:create database test;
创建一个表
格式为:create table 表名(内容 类型);
例:create table student(number int , name char(32), score double);
向表中插入信息
格式为:insert into 表名 values(表中的内容);
例:insert into student values(1, ‘xiaoming’, 99);
从表格中删除信息
格式为:delete from 表名 where 列名 = 条件;
例:delete from student where name = ‘xiaoming’;
查询表中的内容
格式为:select 列名 from 表名 where 列名 = 条件;
例:select score from student where name = ‘xiaoming’;
我们可以用这样的语句查询所有的信息
select * from student;
修改表中的数据
格式为:update 表名 set 列名 = 新内容 where 列名 = 条件;
例:update student set score = 66 where name = ‘xiaoming’;
从数据库中删除一个表
格式为:drop table 表名;
例:drop table student;
我们如果要使用数据库就需要在pro 文件中加上这句话 QT += sql。
首先我们需要自己创建一个数据库,然后利用qt和数据库进行连接。
db = QSqlDatabase::addDatabase(“QMYSQL”);//a
db.setHostName(“127.0.0.1”); //b
db.setDatabaseName(“test”); //c
db.setUserName(“root”); //d
db.setPassword(“123456”); //e
以上的过程就是和数据库进行连接,a表示我们需要使用的是哪种数据库
b是设置主机名,c是设置用户名,表示我们使用哪个数据库, d是设置用户名,e是设置密码,这个密码是和数据库登录时候的密码一致。如果不一致,我们就不能成功和数据库进行连接。
如果连接成功我们就可以通过以上的按钮对数据库进行操作
插入信息到数据库
QString namestr = ui->lineEditName->text(); 获取文本框内容
int num = ui->lineEditNumber->text().toInt();
double score = ui->lineEditScore->text().toDouble();
QString str = QString(“insert into student(num, name, score) values(’%1’, ‘%2’, ‘%3’)”).arg(num).arg(namestr).arg(score);
QSqlQuery query;
query.exec(str);
ui->textEdit->setText(“插入成功”);
时间戳计算时间差值

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值