C++ (Qt)void CheckPause( void ) while (pauseFlag) QThread::sleep(20);}
#ifndef THREE_H#define THREE_Hvoid start(bool stoper);#endif // THREE_H
#include "mainwindow.h"#include <math.h>#include <iostream>using namespace std;#include <thread> //две библиотеки,#include <chrono> //для потоков#include "three.h"#include <stdlib.h>void one(bool stoper){ int i=0; char str[10]; int n=0; FILE* fan; while(stoper==false){ cout<<"i="<<i<<endl; i++; this_thread::sleep_for(chrono::milliseconds(1500)); fan=fopen("test.txt","r"); while(!feof (fan)) { if (fgets(str, 10, fan)) n = atoi(str); cout<<"s="<<str<<endl; this_thread::sleep_for(chrono::milliseconds(1000)); cout<<"n="<<n<<endl; this_thread::sleep_for(chrono::milliseconds(1000)); } this_thread::sleep_for(chrono::milliseconds(3000)); if(n==1){ while(n==1){ cout<< "pause" << endl; this_thread::sleep_for(chrono::milliseconds(1000)); rewind(fan); while(!feof (fan)) { cout<< "@"; if (fgets(str, 10, fan)) n = atoi(str); cout<<"n in pause="<< n << "pause" << endl; } } cout<< "continue" << endl; this_thread::sleep_for(chrono::milliseconds(200)); } //stoper=true; }fclose(fan);}void start(bool stoper){thread th(one,stoper);th.detach();}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow){ ui->setupUi(this); FILE* fn; fn=fopen("test.txt", "w"); fprintf(fn,"111"); fclose(fn);}
bool stoper=false;void MainWindow::on_pushButton_clicked()//старт{ if(stoper==false) start(stoper);}void MainWindow::on_pushButton_2_clicked()//пауза{ FILE* f; f=fopen("test.txt","w"); if(f == NULL) { printf("не могу открыть файл '%s'", "test.txt"); } else fprintf(f,"1"); fclose(f);}void MainWindow::on_pushButton_3_clicked()//продолжить{ FILE* f; f=fopen("test.txt","w"); if(f == NULL) { printf("не могу открыть файл '%s'", "test.txt"); } else fprintf(f,"32"); fclose(f);}