• QT翻金币例子


      main.cpp

    #include "mainscene.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainScene w;
        w.show();
    
        return a.exec();
    }

      mainscene.h

    #ifndef MAINSCENE_H
    #define MAINSCENE_H
    
    #include <QMainWindow>
    #include "chooselevelscene.h"
    namespace Ui {
    class MainScene;
    }
    
    class MainScene : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainScene(QWidget *parent = 0);
        ~MainScene();
    
        //重新paintEvent事件 画背景图
        void paintEvent(QPaintEvent *);
    
        ChooseLevelScene * chooseScene = NULL;
    private:
        Ui::MainScene *ui;
    };
    
    #endif // MAINSCENE_H

    主界面

      mainscene.cpp

    #include "mainscene.h"
    #include "ui_mainscene.h"
    #include <QPainter>
    #include "mypushbutton.h"
    #include <QDebug>
    #include <QTimer>
    MainScene::MainScene(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainScene)
    {
        ui->setupUi(this);
    
        //配置主场景
    
        //设置固定大小
        setFixedSize(320,588);
    
        //设置图标
        setWindowIcon(QIcon(":/res/Coin0001.png"));
    
        //设置标题
        setWindowTitle("翻金币主场景");
    
        //退出按钮实现
        connect(ui->actionQuit,&QAction::triggered,[=](){
            this->close();
        });
    
    
        //开始按钮
        MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
        startBtn->setParent(this);
        startBtn->move( this->width() * 0.5 - startBtn->width() * 0.5 ,this->height() * 0.7 );
    
        //实例化选择关卡场景
        chooseScene = new ChooseLevelScene;
    
    
        //监听选择关卡的返回按钮的信号
        connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
            chooseScene->hide(); //将选择关卡场景 隐藏掉
            this->show(); //重新显示主场景
        });
    
        connect(startBtn,&MyPushButton::clicked,[=](){
            //qDebug() << "点击了开始";
            //做弹起特效
            startBtn->zoom1();
            startBtn->zoom2();
    
    
            //延时进入到选择关卡场景中
            QTimer::singleShot(500,this,[=](){
                //自身隐藏
                this->hide();
                //显示选择关卡场景
                chooseScene->show();
            });
    
    
        });
    }
    
    
    void MainScene::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        QPixmap pix;
        pix.load(":/res/PlayLevelSceneBg.png");
        painter.drawPixmap(0,0,this->width(),this->height(),pix);
    
        //画背景上图标
        pix.load(":/res/Title.png");
    
        pix = pix.scaled( pix.width() * 0.5 , pix.height() * 0.5);
    
        painter.drawPixmap(10,30,pix);
    
    
    }
    
    MainScene::~MainScene()
    {
        delete ui;
    }

    mypushbutton.h

    #ifndef MYPUSHBUTTON_H
    #define MYPUSHBUTTON_H
    
    #include <QPushButton>
    
    class MyPushButton : public QPushButton
    {
        Q_OBJECT
    public:
        //explicit MyPushButton(QWidget *parent = 0);
    
        //构造函数 参数1  正常显示的图片路径   参数2   按下后显示的图片路径
        MyPushButton(QString normalImg, QString pressImg = "" );
    
        //成员属性 保存用户传入的默认显示路径 以及按下后显示的图片路径
        QString normalImgPath;
        QString pressImgPath;
    
    
        //弹跳特效
        void zoom1(); //向下跳
        void zoom2(); //向上跳
    
        //重写按钮 按下 和 释放事件
        void mousePressEvent(QMouseEvent *e);
    
        void mouseReleaseEvent(QMouseEvent *e);
    
    signals:
    
    public slots:
    };
    
    #endif // MYPUSHBUTTON_H

    mypushbutton.cpp

    #include "mypushbutton.h"
    #include <QDebug>
    #include <QPropertyAnimation>
    //MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
    //{
    
    //}
    
    
    MyPushButton::MyPushButton(QString normalImg, QString pressImg )
    {
        this->normalImgPath = normalImg;
        this->pressImgPath = pressImg;
    
        QPixmap pix;
        bool ret = pix.load(normalImg);
        if(!ret)
        {
           qDebug() << "图片加载失败";
           return;
        }
    
        //设置图片固定大小
        this->setFixedSize( pix.width(),pix.height());
    
        //设置不规则图片样式
        this->setStyleSheet("QPushButton{border:0px;}");
    
        //设置图标
        this->setIcon(pix);
    
        //设置图标大小
        this->setIconSize(QSize(pix.width(),pix.height()));
    }
    
    
    void MyPushButton::zoom1()
    {
        //创建动态对象
        QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
        //设置动画时间间隔
        animation->setDuration(200);
    
        //起始位置
        animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
        //结束位置
        animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    
        //设置弹跳曲线
        animation->setEasingCurve(QEasingCurve::OutBounce);
    
        //执行动画
        animation->start();
    }
    void MyPushButton::zoom2()
    {
        //创建动态对象
        QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
        //设置动画时间间隔
        animation->setDuration(200);
    
        //起始位置
        animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
        //结束位置
        animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
    
        //设置弹跳曲线
        animation->setEasingCurve(QEasingCurve::OutBounce);
    
        //执行动画
        animation->start();
    
    }
    
    void MyPushButton::mousePressEvent(QMouseEvent *e)
    {
        if(this->pressImgPath != "") //传入的按下图片不为空 说明需要有按下状态,切换图片
        {
            QPixmap pix;
            bool ret = pix.load(this->pressImgPath);
            if(!ret)
            {
               qDebug() << "图片加载失败";
               return;
            }
    
            //设置图片固定大小
            this->setFixedSize( pix.width(),pix.height());
    
            //设置不规则图片样式
            this->setStyleSheet("QPushButton{border:0px;}");
    
            //设置图标
            this->setIcon(pix);
    
            //设置图标大小
            this->setIconSize(QSize(pix.width(),pix.height()));
    
        }
    
        //让父类执行其他内容
        return QPushButton::mousePressEvent(e);
    
    }
    
    void MyPushButton::mouseReleaseEvent(QMouseEvent *e)
    {
        if(this->pressImgPath != "") //传入的按下图片不为空 说明需要有按下状态,切换成初始图片
        {
            QPixmap pix;
            bool ret = pix.load(this->normalImgPath);
            if(!ret)
            {
               qDebug() << "图片加载失败";
               return;
            }
    
            //设置图片固定大小
            this->setFixedSize( pix.width(),pix.height());
    
            //设置不规则图片样式
            this->setStyleSheet("QPushButton{border:0px;}");
    
            //设置图标
            this->setIcon(pix);
    
            //设置图标大小
            this->setIconSize(QSize(pix.width(),pix.height()));
    
        }
    
        //让父类执行其他内容
        return QPushButton::mouseReleaseEvent(e);
    
    }

    chooselevelscene.h

    #ifndef CHOOSELEVELSCENE_H
    #define CHOOSELEVELSCENE_H
    
    #include <QMainWindow>
    #include "playscene.h"
    class ChooseLevelScene : public QMainWindow
    {
        Q_OBJECT
    public:
        explicit ChooseLevelScene(QWidget *parent = 0);
    
    
        //重写绘图事件
        void paintEvent(QPaintEvent *);
    
        //游戏场景对象指针
        PlayScene * play = NULL;
    
    signals:
        //写一个自定义信号,告诉主场景  点击了返回
        void chooseSceneBack();
    
    public slots:
    };
    
    #endif // CHOOSELEVELSCENE_H

    选择关卡场景

    chooselevelscene.cpp

    #include "chooselevelscene.h"
    #include <QMenuBar>
    #include <QPainter>
    #include "mypushbutton.h"
    #include <QDebug>
    #include <QTimer>
    #include <QLabel>
    ChooseLevelScene::ChooseLevelScene(QWidget *parent) : QMainWindow(parent)
    {
        //配置选择关卡场景
        this->setFixedSize(320,588);
    
        //设置图标
        this->setWindowIcon(QPixmap(":/res/Coin0001.png"));
    
        //设置标题
        this->setWindowTitle("选择关卡场景");
    
        //创建菜单栏
        QMenuBar * bar = menuBar();
        setMenuBar(bar);
    
        //创建开始菜单
        QMenu * startMenu = bar->addMenu("开始");
    
        //创建退出 菜单项
        QAction *  quitAction = startMenu->addAction("退出");
    
        //点击退出 实现退出游戏
        connect(quitAction,&QAction::triggered,[=](){
            this->close();
        });
    
        //返回按钮
        MyPushButton * backBtn = new MyPushButton(":/res/BackButton.png" , ":/res/BackButtonSelected.png");
        backBtn->setParent(this);
        backBtn->move(this->width() - backBtn->width() , this->height() - backBtn->height());
    
        //点击返回
        connect(backBtn,&MyPushButton::clicked,[=](){
            //qDebug() << "点击了返回按钮";
            //告诉主场景 我返回了,主场景监听ChooseLevelScene的返回按钮
            //延时返回
            QTimer::singleShot(500,this,[=](){
                emit this->chooseSceneBack();
            });
    
        });
    
        //创建选择关卡的按钮
        for( int i = 0 ; i < 20 ;i ++)
        {
            MyPushButton * menuBtn = new MyPushButton(":/res/LevelIcon.png");
            menuBtn->setParent(this);
            menuBtn->move( 25 + i%4 * 70 , 130 + i/4 * 70  );
    
            //监听每个按钮的点击事件
            connect(menuBtn,&MyPushButton::clicked,[=](){
                QString str = QString("您选择的是第 %1 关 ").arg( i + 1);
                qDebug() <<str;
    
                //进入到游戏场景
                this->hide(); //将选关场景隐藏掉
                play = new PlayScene(i+1); //创建游戏场景
                play->show();//显示游戏场景
    
                connect(play,&PlayScene::chooseSceneBack,[=](){
                    this->show();
                    delete play;
                    play = NULL;
                });
    
            });
    
            QLabel * label = new QLabel;
            label->setParent(this);
            label->setFixedSize(menuBtn->width(),menuBtn->height());
            label->setText(QString::number(i+1));
            label->move(25 + i%4 * 70 , 130 + i/4 * 70 );
    
            //设置 label上的文字对齐方式 水平居中和 垂直居中
            label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
            //设置让鼠标进行穿透   51号属性
            label->setAttribute(Qt::WA_TransparentForMouseEvents);
        }
    
    
    
    }
    
    void ChooseLevelScene::paintEvent(QPaintEvent *)
    {
        //加载背景
        QPainter painter(this);
        QPixmap pix;
        pix.load(":/res/OtherSceneBg.png");
        painter.drawPixmap(0,0,this->width(),this->height(),pix);
    
        //加载标题
        pix.load(":/res/Title.png");
        painter.drawPixmap( (this->width() - pix.width())*0.5,30,pix.width(),pix.height(),pix);
    
    
    }

    playscene.h

    #ifndef PLAYSCENE_H
    #define PLAYSCENE_H
    
    #include <QMainWindow>
    #include <QTimer>
    #include "mycoin.h"
    
    class PlayScene : public QMainWindow
    {
        Q_OBJECT
    public:
        PlayScene(int level);
        void paintEvent(QPaintEvent* event);
    
        int levelIndex;
        int gameArray[4][4];
        MyCoin* coinArray[4][4];
        bool isWin;
    
    signals:
        void chooseSceneBack();
    };
    
    #endif // PLAYSCENE_H

    游戏场景

    playscene.cpp

    #include "playscene.h"
    #include <QMenuBar>
    #include <QPainter>
    #include "mypushbutton.h"
    #include <QTimer>
    #include <QLabel>
    #include "mycoin.h"
    #include "dataconfig.h"
    #include <QDebug>
    #include <QPropertyAnimation>
    #include <QSound>
    
    PlayScene::PlayScene(int level)
    {
        this->levelIndex = level;
    
        this->setFixedSize(320,588);
        this->setWindowIcon(QIcon(":/res/Coin0001.png"));
        QString str = QString("關卡%1").arg(level);
        this->setWindowTitle(str);
    
        QMenuBar* menuBar = this->menuBar();
        this->setMenuBar(menuBar);
        QMenu* startMenu = new QMenu("開始");
        menuBar->addMenu(startMenu);
        QAction* quitAction = startMenu->addAction("退出");
    
        connect(quitAction,&QAction::triggered,[=](){
            this->close();
        });
    
        dataConfig config;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                gameArray[i][j] = config.mData[this->levelIndex][i][j];
            }
        }
        //返回按鈕音效
        QSound *backSound = new QSound(":/res/BackButtonSound.wav",this);
        //翻金幣音效
        QSound *flipSound = new QSound(":/res/ConFlipSound.wav",this);
        //勝利按鈕音效
        QSound *winSound = new QSound(":/res/LevelWinSound.wav",this);
    
    
    
    
        //勝利Label
        QLabel* winLabel = new QLabel;
        QPixmap tmpPix;
        tmpPix.load(":/res/LevelCompletedDialogBg.png");
        winLabel->setGeometry(0,0,tmpPix.width(),tmpPix.height());
        winLabel->setPixmap(tmpPix);
        winLabel->setParent(this);
        winLabel->move( (this->width() - tmpPix.width())*0.5 , -tmpPix.height());
    
    
        //創建金幣的背景圖片
        for(int i = 0 ; i < 4;i++)
        {
            for(int j = 0 ; j < 4; j++)
            {
               //繪製背景圖片
                QPixmap pixMap(":/res/BoardNode.png");
                QLabel* label = new QLabel;
                label->setGeometry(0,0,pixMap.width(),pixMap.height());
                label->setPixmap(pixMap);
                label->setParent(this);
                label->move(57 + i*50,200+j*50);
    
                //創建金幣
                QString str;
                if(gameArray[i][j]==1){
                    str = ":/res/Coin0001.png";
                }else{
                    str = ":/res/Coin0008.png";
                }
                MyCoin* myCoin = new MyCoin(str);
                myCoin->setParent(this);
                myCoin->move(59 + i*50,204+j*50);
                myCoin->posX = i;
                myCoin->posY = j;
                myCoin->coinFlag = gameArray[i][j];
    
                this->coinArray[i][j] = myCoin;
    
                connect(myCoin,&QPushButton::clicked,[=](){
                    flipSound->play();
                    //點擊時將其他金幣按鈕先禁用
                    for(int i=0;i<4;i++){
                        for(int j=0;j<4;j++){
                           coinArray[i][j]->isWin = true;
                        }
                    }
    
    
                   myCoin->changeFlag();
                   gameArray[i][j] = gameArray[i][j]==0?1:0;
    
                   QTimer::singleShot(300,this,[=](){
                       //右邊金幣翻轉
                      if(myCoin->posX+1<=3){
                          coinArray[myCoin->posX+1][myCoin->posY]->changeFlag();
                          gameArray[myCoin->posX+1][myCoin->posY] = gameArray[myCoin->posX+1][myCoin->posY]==0?1:0;
                      }
                      //左邊金幣翻轉
                     if(myCoin->posX-1>=0){
                         coinArray[myCoin->posX-1][myCoin->posY]->changeFlag();
                         gameArray[myCoin->posX-1][myCoin->posY] = gameArray[myCoin->posX-1][myCoin->posY]==0?1:0;
                     }
                     //上邊邊金幣翻轉
                    if(myCoin->posY-1>=0){
                        coinArray[myCoin->posX][myCoin->posY-1]->changeFlag();
                        gameArray[myCoin->posX][myCoin->posY-1] = gameArray[myCoin->posX][myCoin->posY-1]==0?1:0;
                    }
                    //下邊邊金幣翻轉
                   if(myCoin->posY+1<=3){
                       coinArray[myCoin->posX][myCoin->posY+1]->changeFlag();
                       gameArray[myCoin->posX][myCoin->posY+1] = gameArray[myCoin->posX][myCoin->posY+1]==0?1:0;
                   }
    
                    //點擊後再解禁
                   for(int i=0;i<4;i++){
                       for(int j=0;j<4;j++){
                          coinArray[i][j]->isWin = false;
                       }
                   }
    
                   //判斷贏未
                   this->isWin = true;
                   for(int i=0;i<4;i++){
                       for(int j=0;j<4;j++){
                           if(coinArray[i][j]->coinFlag==false){
                               this->isWin = false;
                               break;
                           }
                       }
                   }
                   if(this->isWin){
                       winSound->play();
                       qDebug()<<"YOU WIN!!!!";
                       for(int i=0;i<4;i++){
                           for(int j=0;j<4;j++){
                               coinArray[i][j]->isWin = true;
                           }
                       }
                       QPropertyAnimation* animation = new QPropertyAnimation(winLabel,"geometry");
                       animation->setDuration(1000);
                       animation->setStartValue(QRect(winLabel->x(),winLabel->y(),winLabel->winId(),winLabel->height()));
                       animation->setEndValue(QRect(winLabel->x(),-winLabel->y(),winLabel->winId(),winLabel->height()));
                       animation->setEasingCurve(QEasingCurve::OutBounce);
                       animation->start();
                   }
    
                   });
    
    
                });
            }
        }
    
        MyPushButton* backBtn = new MyPushButton(":/res/BackButton.png",":/res/BackButtonSelected.png");
        backBtn->setParent(this);
        backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());
    
        connect(backBtn,&QPushButton::clicked,[=](){
            backSound->play();
            //延時發送返回信號
            QTimer::singleShot(200,this,[=](){
                emit this->chooseSceneBack();
            });
    
        });
    
        QLabel* label = new QLabel(this);
        QFont font;
        font.setFamily("微軟正黑體");
        font.setPointSize(20);
        label->setFont(font);
        QString str1 = QString("Level:%1").arg(this->levelIndex);
        label->setText(str1);
        label->setGeometry(30, this->height() - 50,120, 50);
    
    }
    
    void PlayScene::paintEvent(QPaintEvent* event){
        QPainter painter(this);
        QPixmap pix;
        pix.load(":/res/PlayLevelSceneBg.png");
        painter.drawPixmap(0,0,this->width(),this->height(),pix);
    
        pix.load(":/res/Title.png");
        pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
        painter.drawPixmap(10,30,pix);
    }

    声音播放需要在pro中增加 multimedia

    QT       += core gui multimedia

    mycoin.h

    #ifndef MYCOIN_H
    #define MYCOIN_H
    
    #include <QPushButton>
    #include <QTimer>
    
    class MyCoin : public QPushButton
    {
        Q_OBJECT
    public:
        MyCoin(QString butImg);
        void changeFlag();
        void mousePressEvent(QMouseEvent* event);
    
        int posX;
        int posY;
        bool coinFlag; //1正 0反
        QTimer* timer1 = NULL; //正->反
        QTimer* timer2 = NULL; //反->正
        int min = 1;
        int max = 8;
        bool isAnimation = false;
        bool isWin = false;
    
    signals:
    
    };
    
    #endif // MYCOIN_H

    mycoin.cpp

    #include "mycoin.h"
    #include <QDebug>
    
    
    
    MyCoin::MyCoin(QString butImg){
        QPixmap pixMap;
        bool ret = pixMap.load(butImg);
        if(!ret){
            qDebug()<<"圖片加載失敗";
        }
    
        this->setFixedSize(pixMap.width(),pixMap.height());
        this->setStyleSheet("QPushButton{border:0px}");
        this->setIcon(pixMap);
        this->setIconSize(QSize(pixMap.width(),pixMap.height()));
    
        timer1 = new QTimer(this);
        timer2 = new QTimer(this);
    
        connect(timer1,&QTimer::timeout,[=](){
           QPixmap pixMap;
           QString str = QString(":/res/Coin000%1").arg(this->min++);
           pixMap.load(str);
    
           this->setFixedSize(pixMap.width(),pixMap.height());
           this->setStyleSheet("QPushButton{border:0px}");
           this->setIcon(pixMap);
           this->setIconSize(QSize(pixMap.width(),pixMap.height()));
    
           if(this->min>this->max){
               this->min = 1;
               this->isAnimation = false;
               timer1->stop();
           }
    
        });
    
        connect(timer2,&QTimer::timeout,[=](){
           QPixmap pixMap;
           QString str = QString(":/res/Coin000%1").arg(this->max--);
           pixMap.load(str);
    
           this->setFixedSize(pixMap.width(),pixMap.height());
           this->setStyleSheet("QPushButton{border:0px}");
           this->setIcon(pixMap);
           this->setIconSize(QSize(pixMap.width(),pixMap.height()));
    
           if(this->max<this->min){
               this->max = 8;
               this->isAnimation = false;
               timer2->stop();
           }
    
        });
    }
    
    void MyCoin::changeFlag(){
        if(this->coinFlag){
            timer1->start(30); //正->反
            this->isAnimation = true;
            this->coinFlag = false;
        }else{
            timer2->start(30); //反->正
            this->isAnimation = true;
            this->coinFlag = true;
        }
    }
    
    void MyCoin::mousePressEvent(QMouseEvent* event){
        if(!this->isAnimation&&!this->isWin){
            QPushButton::mousePressEvent(event);
        }
    }

      dataconfig.h  数据配置,关卡金币与银币的初始状态

    #ifndef DATACONFIG_H
    #define DATACONFIG_H
    
    #include <QObject>
    #include <QMap>
    #include <QVector>
    
    class dataConfig : public QObject
    {
        Q_OBJECT
    public:
        explicit dataConfig(QObject *parent = 0);
    
    public:
    
        QMap<int, QVector< QVector<int> > >mData;
    
    
    
    signals:
    
    public slots:
    };
    
    #endif // DATACONFIG_H

      dataconfig.cpp

    #include "dataconfig.h"
    #include <QDebug>
    dataConfig::dataConfig(QObject *parent) : QObject(parent)
    {
    
         int array1[4][4] = {{1, 1, 1, 1},
                            {1, 1, 0, 1},
                            {1, 0, 0, 0},
                            {1, 1, 0, 1} } ;
    
         QVector< QVector<int>> v;
         for(int i = 0 ; i < 4;i++)
         {
             QVector<int>v1;
             for(int j = 0 ; j < 4;j++)
             {
    
                v1.push_back(array1[i][j]);
             }
             v.push_back(v1);
         }
    
         mData.insert(1,v);
    
    
         int array2[4][4] = { {1, 0, 1, 1},
                              {0, 0, 1, 1},
                              {1, 1, 0, 0},
                              {1, 1, 0, 1}} ;
    
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array2[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(2,v);
    
    
    
         int array3[4][4] = {  {0, 0, 0, 0},
                               {0, 1, 1, 0},
                               {0, 1, 1, 0},
                               {0, 0, 0, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array3[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(3,v);
    
    
         int array4[4][4] = {   {0, 1, 1, 1},
                                {1, 0, 0, 1},
                                {1, 0, 1, 1},
                                {1, 1, 1, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array4[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(4,v);
    
    
         int array5[4][4] = {  {1, 0, 0, 1},
                               {0, 0, 0, 0},
                               {0, 0, 0, 0},
                               {1, 0, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array5[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(5,v);
    
    
         int array6[4][4] = {   {1, 0, 0, 1},
                                {0, 1, 1, 0},
                                {0, 1, 1, 0},
                                {1, 0, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array6[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(6,v);
    
    
         int array7[4][4] = {   {0, 1, 1, 1},
                                {1, 0, 1, 1},
                                {1, 1, 0, 1},
                                {1, 1, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array7[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(7,v);
    
         int array8[4][4] = {  {0, 1, 0, 1},
                               {1, 0, 0, 0},
                               {0, 0, 0, 1},
                               {1, 0, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array8[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(8,v);
    
         int array9[4][4] = {   {1, 0, 1, 0},
                                {1, 0, 1, 0},
                                {0, 0, 1, 0},
                                {1, 0, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array9[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(9,v);
    
    
    
         int array10[4][4] = {  {1, 0, 1, 1},
                                {1, 1, 0, 0},
                                {0, 0, 1, 1},
                                {1, 1, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array10[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(10,v);
    
    
         int array11[4][4] = {  {0, 1, 1, 0},
                                {1, 0, 0, 1},
                                {1, 0, 0, 1},
                                {0, 1, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array11[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(11,v);
    
         int array12[4][4] = {  {0, 1, 1, 0},
                                {0, 0, 0, 0},
                                {1, 1, 1, 1},
                                {0, 0, 0, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array12[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(12,v);
    
    
         int array13[4][4] = {    {0, 1, 1, 0},
                                  {0, 0, 0, 0},
                                  {0, 0, 0, 0},
                                  {0, 1, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array13[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(13,v);
    
         int array14[4][4] = {    {1, 0, 1, 1},
                                  {0, 1, 0, 1},
                                  {1, 0, 1, 0},
                                  {1, 1, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array14[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(14,v);
    
    
         int array15[4][4] = {   {0, 1, 0, 1},
                                 {1, 0, 0, 0},
                                 {1, 0, 0, 0},
                                 {0, 1, 0, 1}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array15[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(15,v);
    
    
         int array16[4][4] = {   {0, 1, 1, 0},
                                 {1, 1, 1, 1},
                                 {1, 1, 1, 1},
                                 {0, 1, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array16[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(16,v);
    
         int array17[4][4] = {  {0, 1, 1, 1},
                                {0, 1, 0, 0},
                                {0, 0, 1, 0},
                                {1, 1, 1, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array17[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(17,v);
    
    
         int array18[4][4] = { {0, 0, 0, 1},
                               {0, 0, 1, 0},
                               {0, 1, 0, 0},
                               {1, 0, 0, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array18[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(18,v);
    
         int array19[4][4] = {   {0, 1, 0, 0},
                                 {0, 1, 1, 0},
                                 {0, 0, 1, 1},
                                 {0, 0, 0, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array19[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(19,v);
    
         int array20[4][4] = {  {0, 0, 0, 0},
                                {0, 0, 0, 0},
                                {0, 0, 0, 0},
                                {0, 0, 0, 0}} ;
         v.clear();
         for(int i = 0 ; i < 4;i++)
         {
              QVector<int>v1;
              for(int j = 0 ; j < 4;j++)
              {
                 v1.push_back(array20[i][j]);
              }
              v.push_back(v1);
         }
    
         mData.insert(20,v);
    
    
         //测试数据
    //    for( QMap<int, QVector< QVector<int> > >::iterator it = mData.begin();it != mData.end();it++ )
    //    {
    //         for(QVector< QVector<int> >::iterator it2 = (*it).begin(); it2!= (*it).end();it2++)
    //         {
    //            for(QVector<int>::iterator it3 = (*it2).begin(); it3 != (*it2).end(); it3++ )
    //            {
    //                qDebug() << *it3 ;
    //            }
    //         }
    //         qDebug() << endl;
    //    }
    
    
    }

    项目连接地址:https://gitee.com/qiaokuankuan/QtLearn.git

  • 相关阅读:
    基于C++CJAVA的python入门
    雁栖湖健身计划
    显存的一些知识
    Cuda_bank-conflict
    翻译文章进展
    一些CV界的好资源
    how processor caches work
    LINQ-进阶的扩展方法
    LINQ-基础
    CTFHUB-技能树 基础知识 ctf练习平台
  • 原文地址:https://www.cnblogs.com/wuyuan2011woaini/p/16285065.html
Copyright © 2020-2023  润新知