qtday02 qt做简单的加法器和模拟登陆功能

//在3t2目录下
//adder.h
/*
qt简单加法计算器
*/
#ifndef ADDER_H
#define ADDER_H
#include<QDialog>
#include<QLineEdit>
#include<QtWidgets/QPushButton>
#include<QtWidgets/QLabel>
class Adder:public QDialog{
    Q_OBJECT//让自定义的槽函数生效
    private:
        QLineEdit * add1;
        QLabel * oper;
        QLineEdit *add2;
        QPushButton * equ;
        QLineEdit * res;
        QPushButton * bclose;
    public:
        Adder();
        ~Adder();
        /*自定义槽函数*/
    public slots:
        void getres();
    
};

#endif

//adder.cpp
#include "adder.h"
/*#include<QDialog>
#include<QLineEdit>
#include<QtWidgets/QPushButton>
#include<QtWidgets/QLabel>
*/
Adder::Adder(){
    this->resize(400,300);
    add1=new QLineEdit(this);
    add1->resize(80,20);
    add1->move(0,20);
    oper=new QLabel("+",this);
    oper->resize(20,20);
    oper->move(80,20);
    add2=new QLineEdit(this);
    add2->resize(80,20);
    add2->move(100,20);
    equ=new QPushButton("=",this);
    equ->resize(20,20);
    equ->move(180,20);
    res=new QLineEdit(this);
    res->resize(80,20);
    res->move(200,20);
    bclose=new QPushButton("close",this);
    bclose->resize(80,20);
    bclose->move(160,160);
    connect(bclose,SIGNAL(clicked()),this,SLOT(close()));
    connect(equ,SIGNAL(clicked()),this,SLOT(getres()));
}
Adder::~Adder(){
    delete add1;
    delete oper;
    delete add2;
    delete equ;
    delete res;
    delete bclose;
}
void Adder::getres(){
    int c=add1->text().toInt()+add2->text().toInt();
    /*
    QString qa=add1->text();
    QString qb=add2->text();
    int a=qa.toInt();
    int b=qb.toInt();
    int c=a+b;
     */
    res->setText(QString::number(c));
}
//qq.h
/*模拟qq登陆*/
#ifndef QQ_H
#define QQ_H
#include<QDialog>
#include<QLineEdit>
#include<QtWidgets/QPushButton>
#include<QtWidgets/QLabel>
class QQ:public QDialog
{
    Q_OBJECT
    private:
        QLineEdit * username;
        QLineEdit* userpwd;
        QPushButton * login;
        QPushButton* cancel;
    public:
        QQ();
        ~QQ();
        /*函数,登陆和退出*/
        public slots:
            void loginAndcancel();
};
#endif
//qq.cpp
#include "qq.h"
QQ::QQ()
{
    this->resize(400,300);
    username=new QLineEdit(this);
    username->resize(80,20);
    username->move(60,20);

    userpwd=new QLineEdit(this);
    userpwd->resize(80,20);
    userpwd->move(60,50);
    userpwd->setEchoMode(QLineEdit::Password);

    login=new QPushButton("login",this);
    login->resize(60,20);
    login->move(20,80);

    cancel=new QPushButton("cancel",this);
    cancel->resize(60,20);
    cancel->move(100,80);
    connect(login,SIGNAL(clicked()),this,SLOT(loginAndcancel()));
    connect(cancel,SIGNAL(clicked()),this,SLOT(loginAndcancel()));
}
QQ::~QQ()
{
    delete username;
    delete userpwd;
    delete login;
    delete cancel;
}
#include<QMessageBox>
void QQ::loginAndcancel()
{
    /**/
    QPushButton *b=(QPushButton*)sender();
    if(b->text()=="login"){
        if(username->text()=="admin"&& userpwd->text()=="123"){
        qDebug("login success!");
        }
        else{
        qDebug("login failed");
        }
    }
    else if(b->text()=="cancel"){
        QMessageBox msg;//退出时提示
        msg.setText("要退出吗?");
        msg.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
        if(msg.exec()==QMessageBox::Yes){
        this->close();
        }
    
    }

}

//gettime.h
/*界面显示获取的当前时间 */
#ifndef GETTIME_H
#define GETTIME_H
#include<QDialog>
#include<QLineEdit>
#include<QtWidgets/QPushButton>
#include<QtWidgets/QLabel>
class GetTime:public QDialog{
    Q_OBJECT
    private:
        QLabel *res;
        QPushButton *gettime;
    public:
        GetTime();
        ~GetTime();
    public slots:
        void settime();
    //方案2,信号连接
    public:signals:
           void ssettime(QString par);
    
};
#endif
//gettime.cpp
#include "gettime.h"
GetTime::GetTime()
{
    this->resize(400,300);
    res=new QLabel("Cur Time",this);
    gettime=new QPushButton("gettime",this);
    gettime->move(0,50);
    connect(gettime,SIGNAL(clicked()),this,SLOT(settime()));
    connect(this,SIGNAL(ssettime(QString)),res,SLOT(setText(QString)));
    //connect(this);
}
GetTime::~GetTime()
{
    delete res;
    delete gettime;
}
#include<QTime>
/*
#include<time.h>
#include<stdio.h>
*/
void GetTime::settime(){
    /*
    struct tm *tm1=localtime(time(0));
    char buf[200];
    sprintf(buf,"%4d-%2d-%2d %2d:%2d:%2d",tm1->tm_year+1700,
            tm1->tm_mon+1,tm1->tm_mday,
            tm1->tm_hour,tm1->tm_min,tm1->tm_sec);
    res->setText(buf);
    */
    /*
    //1 直接调用res槽函数,设置值
    res->setText(QTime::currentTime().toString("HH:mm:ss"));
    */
    /*方案2,发送带参数的信号,再由信号参数去触发res的槽函数 emit */
    emit ssettime(QTime::currentTime().toString("HH:mm:ss"));
}

//main.cpp
/*测试上面三个功能 */
/*
 qt做简单的加法计算器
 */
#include<QApplication>
#include "adder.h"
#include "qq.h"
#include "gettime.h"
int main(int argc,char * argv[])
{
    QApplication app(argc,argv);
    /*简单加法器
    Adder add1;
    add1.show();
    */
    /*qq登陆框
    QQ qq;
    qq.show();
    */
    /**/
    GetTime t;
    t.show();
    //qDebug("output");//在控制台上输出信息
    app.exec();
}

时间: 2024-07-31 08:51:00

qtday02 qt做简单的加法器和模拟登陆功能的相关文章

求助,哪位大神能帮忙写个模拟登陆csdn的程序,我拿来做例子,研究httpclient模拟登陆,谢谢

问题描述 求助,哪位大神能帮忙写个模拟登陆csdn的程序,我拿来做例子,研究httpclient模拟登陆,谢谢 求助哪位大神能帮忙写个模拟登陆csdn的程序,我拿来做例子,研究httpclient模拟登陆,谢谢 解决方案 http://blog.csdn.net/njchenyi/article/details/38801287 解决方案二: 报错了....能直接发我个么..= =初学者,并不太懂,谢谢

java web 技术-求助!关于模拟登陆利用接收的cookie判断登录是否成功,遇到了问题,,求大神们相助!在下多谢!

问题描述 求助!关于模拟登陆利用接收的cookie判断登录是否成功,遇到了问题,,求大神们相助!在下多谢! 在下学生最近在做一个用java开发模拟登陆校内网的项目,可是学校使用struts2做的,url的尾缀是.action,登陆前和登陆后的url一致,无法用html来判断,,于是就想用cookie来判断登陆是否成功,可是面临一个问题就是请求标头的Cookie是JSESSIONID=3CDAB1BA4520BD1F53E62F9D5BCCCC49之类的,发送的jsessionid和接收的jses

使用Qt做一个简易音乐播放器[Phonon浅谈--续]

2010-2-13 使用Qt做一个简易音乐播放器[Phonon浅谈--续]   在第一篇Phonon浅谈中提及到了Phonon这个多媒体框架的一些基本知识,于是想着结合这些基本知识来实践一番,做一个简单的音乐播放器.   [步骤一] 新建一个Qt Gui工程,在建立过程中需要包含Phonon模块,之后生成文件如下图: Qt Gui工程会生成一个ui文件,在这里是mainwindow.ui.双击mainwindow.ui进行一番简单的布局,如下图: 关于这个ui界面,中央位置是一个QListWid

用原生JS对AJAX做简单封装的实例代码_javascript技巧

首先,我们需要xhr对象.这对我们来说不难,封装成一个函数. var createAjax = function() { var xhr = null; try { //IE系列浏览器 xhr = new ActiveXObject("microsoft.xmlhttp"); } catch (e1) { try { //非IE浏览器 xhr = new XMLHttpRequest(); } catch (e2) { window.alert("您的浏览器不支持ajax,请

有人做过java httpclient 模拟登陆outlook 获取邮件的吗

问题描述 有人做过java httpclient 模拟登陆outlook 获取邮件的吗 有人做过java httpclient 模拟登陆outlook 获取邮件的吗 解决方案 其实现在很多可以做模拟登录的httpClient,JSOUP,htmlUnit,我做过用Jsoup做模拟登录,要做两次模拟,第一次是获得Cookie,第二次带入cookie就行了,大致思想就是这样. 解决方案二: 这种程序没有意义,因为网页是不断变化的,你应该用mapi从本地outlook获取,或者用pop协议从邮箱服务器

程序文件-怎么用mf或者qt做个题库

问题描述 怎么用mf或者qt做个题库 题库设计(1) 包括选择判断填空和问答(2) 可以自动改选择和判断(3) 分为平常和考试2个模式(4) 界面在网页或者windows的窗口界面(5) 可以错题统计和分数统计 就和一些试题集带的光盘那种题库一样.或者别的也行,用c语言的话.难吗 解决方案 有没有大神,帮下忙,期末作业.难吗

用qt做的浏览器,加载百度页面出错

问题描述 用qt做的浏览器,加载百度页面出错 初学qt 做了一个浏览器浏览网页,加载百度时出错: 注意红框处,正常浏览器加载百度页面时换一换可用,图片可滚动显示,我做的无法滚动显示图片,换一换不可用 解决方案 页面出错了,可能你的浏览器控件支持不够好 解决方案二: 还有就是百度搜索新浪微博,点击之后地址栏加载http://passport.weibo.com/visitor/visitor?entry=miniblog&a=enter&url=http%3A%2F%2Fweibo.com%

用qt做GUI,求交流社区或论坛网站

问题描述 用qt做GUI,求交流社区或论坛网站 我是个新手,刚入行做开发,现在的项目是用qt做的一个车载娱乐系统平台,我们公司负责GUI这层.现在我接手了一个短信模块,入职才一个月-- 感觉好沮丧,女生本来就少,不能让人看不起-不仅bug一个没解决,改页面之后现在第二个页面一进去就黑的,折腾了两三天还没解决,请问有没有GUI相关的社区论坛?或者有没有前辈愿意指导一下新手该如何立足于行业 解决方案 自从有了stackoverflow以后,我觉得没必要去别的论坛提问了.其它论坛的回答质量还不如goo

网站 客户系统-推荐做简单的网站系统(客户信息列表)好的公司

问题描述 推荐做简单的网站系统(客户信息列表)好的公司 想做一个比较简单的系统,上面是公司客户的信息,有二十个条目的样子. 想用开源软件和标准技术来做,做在外网上,以用户名密码登陆,供全公司使用. 系统要实现的就是简便输入,各种维度的查询,导出列表,设置权限等很基本的功能. 不知道有没有做这类似系统很不错的公司呀,希望大家推荐一些靠谱的,团队技术好经验较丰富优先. 我现在是在北京,请大家帮忙,谢谢!