调用exe

//      http://tieba.baidu.com/p/3406210950

 1 #include <QCoreApplication>
 2 #include <QProcess>
 3 #include <QDebug>
 4 int main(int argc, char *argv[])
 5 {
 6     QCoreApplication a(argc, argv);
 7 
 8 
 9     QProcess process;
10 //    process.execute("calc");
11 
12 qDebug()<<"start";
13     process.execute("../SnakeChess/debug/SnakeChess.exe");//鐩稿浜庝唬鐮佺殑浣嶇疆
14     process.start("../SnakeChess/debug/SnakeChess.exe");
15     qDebug()<<"end";
16     return a.exec();
17 }

2、蛇棋(未完)

#include <QCoreApplication>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <random>
#include <ctime>
#include <QTime>
using namespace std;
class Player
{
public:
  Player()
  {
      std::cout<<"constructor"<<std::endl;
      m_time=0;
      m_num=0;
  }
  void run()
  {
      if(m_num>=100)
          return;

      runOnce();

      run();
      return;
  }
public:
  void runOnce()
  {

      //int dice=rand()%6;
//      std::random_device rd;
//      std::mt19937 mt(rd());
//      int dice=mt()%6;
      //qsrand(time(NULL));
      //int dice= qrand()%6+1;

      QTime time;
      time= QTime::currentTime();
      qsrand(time.msec()+time.second()*1000);
      int dice = qrand() %6+1;
      m_num+=dice;

      ++m_time;
      std::cout<<"m_time:"<<m_time<<std::endl;
      std::cout<<"m_num:"<<m_num<<std::endl;

      if(m_num==6)
          this->runOnce();
  }

  ~Player()
  {
      std::cout<<"~destructor"<<std::endl;
  }
private:
  int m_num;
  int m_time;
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);


    Player p;
    p.run();
    delete &p;

    return a.exec();
}

猜你喜欢

转载自www.cnblogs.com/wangbin-heng/p/10367295.html