真爱无限的知识驿站

学习积累技术经验,提升自身能力

qtday03 简单版的贪吃蛇游戏

//snakegame.h

#ifndef SNAKEGAME_H
#define SNAKEGAME_H
#include<QList>
#include<QtWidgets/QLabel>
#include<QtWidgets/QDialog>
#include<QKeyEvent>
#include<QTimer>
/*枚举,表示方向*/
enum Direction{D_UP,D_DOWN,D_LEFT,D_RIGHT};
class SnakeGame:public QDialog
{
    Q_OBJECT
public:
    SnakeGame() ;
    ~SnakeGame();
public slots:
    void snakemove();/*移动*/
public:
    QLabel* getfood();/*产生新食物*/
    void keyPressEvent(QKeyEvent *key);
private:
    QList<QLabel*> snake;/*蛇*/
    QLabel * food;/*食物*/
    Direction dire;/*方向*/
    int foodlen;/*食物长度*/
    int maxlen;/*最大长度*/
    QTimer * timer;/*定时器*/
};
#endif // SNAKEGAME_H


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


qtday01 ubuntu 下手动编写第一个qt程序

//qt 5.2.1

//1t目录下

//1t.cpp

/*
 第一个qt程序
 */
#include <QApplication>
#include<QtWidgets/QLabel>
#include<QString>
#include<QTextCodec>
int main(int argc,char** argv){
    /*构造一个对象*/
    QApplication app(argc,argv);
    QTextCodec* coder=QTextCodec::codecForName("utf-8");
    /*设置编码对象*/
//    QTextCodec::setCodecForTr(coder);
    //set code to the words
    //QLabel qlab(QObject::tr("hello qt你好 ,today is a nice day!"));
    QLabel qlab(coder->toUnicode("hello qt你好 ,today is a nice day!"));
    qlab.show();
    /*让程序进入事件循环*/
    return app.exec();
}

//在1t目录下,输入命令:

<< 1 >>

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号