//класс параллельного потока обработки данныхclass MyThread : public QThread, public Ui::MainWindow{ Q_OBJECTpublic: volatile bool stopped; MyThread(){ stopped = false; }; ~MyThread() {}; char flag1, flag2; void run() { while (!stopped) { mutex.lock(); if(flag2==1) { flag2=0; emit s21();} mutex.unlock(); } } void MyThread::stop() { stopped = true; } signals: void s21(void); private: QMutex mutex; //конструктор главной формыfrmMain::frmMain() : QWidget(0, Qt::Window){ connect(pushButton_8, SIGNAL(clicked()), SLOT(an_t0())); connect(&thread1, SIGNAL(s21()), SLOT(an_t21()));}void frmMain::an_t0(){ if(lst.at(0).toInt()==21) { thread1.start(QThread::LowPriority); thread1.flag2=1; }void frmMain::an_t21(){ //обработка данных
C++ (Qt) ThreadFunctionResult forThreadFunction() { BlockSizeManagerV2 blockSizeManager(iterationCount); ResultReporter<T> resultReporter(this); for(;;) { if (this->isCanceled()) break; const int currentBlockSize = blockSizeManager.blockSize(); if (currentIndex.load() >= iterationCount) break; // Atomically reserve a block of iterationCount for this thread. const int beginIndex = currentIndex.fetchAndAddRelease(currentBlockSize); const int endIndex = qMin(beginIndex + currentBlockSize, iterationCount); if (beginIndex >= endIndex) { // No more work break; } this->waitForResume(); // (only waits if the qfuture is paused.) if (shouldStartThread()) this->startThread(); const int finalBlockSize = endIndex - beginIndex; // block size adjusted for possible end-of-range resultReporter.reserveSpace(finalBlockSize); // Call user code with the current iteration range. blockSizeManager.timeBeforeUser(); const bool resultsAvailable = this->runIterations(begin, beginIndex, endIndex, resultReporter.getPointer()); blockSizeManager.timeAfterUser(); if (resultsAvailable) resultReporter.reportResults(beginIndex); // Report progress if progress reporting enabled. if (progressReportingEnabled) { completed.fetchAndAddAcquire(finalBlockSize); this->setProgressValue(this->completed.load()); } if (this->shouldThrottleThread()) return ThrottleThread; } return ThreadFinished; }