Risolti alcuni bug + shourtcut
[qmemory] / testThread.cpp
1 #include "testThread.h"
2 #include <QTimer>
3 #include <qdebug.h>
4 #include <QMessageBox>
5 #include <QDateTime>
6
7 TestThread::TestThread(QObject *parent):QThread(parent)
8 {
9     colore=0;
10     index=0;
11     _score=0;
12     qsrand(QDateTime::currentDateTime().toTime_t());
13
14 }
15
16 TestThread::~TestThread()
17 {
18
19 }
20 void TestThread::run(){
21     sleep(2);
22     forever{
23         mutex.lock();
24
25         qsrand(QDateTime::currentDateTime().toTime_t());
26         sequenza.append(qrand()%9);
27         int i=0;
28         index=0;
29
30         emit disableInterface();
31         while(i<sequenza.size())
32         {
33           emit generate(sequenza.at(i));
34           msleep(500 - (_score*2));
35           emit generate(sequenza.at(i));
36           msleep(500 - (_score*2));
37           i++;
38         }
39         i=0;
40         emit enableInterface();
41         attendiInputUtente.wait(&mutex);
42
43         mutex.unlock();
44
45     }
46
47
48 }
49
50 void TestThread::addUserInput(int inputUser){
51         if(sequenza.at(index)==inputUser)
52         {
53             index++;
54             _score++;
55             emit score(_score);
56             if(index==sequenza.size()){
57                 sleep(1);
58                 attendiInputUtente.wakeAll();
59
60             }
61         }
62         else{
63             emit exit(_score);
64             _score=0;
65             sequenza.clear();
66             index=0;
67             attendiInputUtente.wakeAll();
68         }
69
70 }
71
72 void TestThread::genera()
73 {
74
75     attendiInputUtente.wakeAll();
76
77 }