projects
/
qmemory
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Inserita la QwaitCondition
[qmemory]
/
testThread.cpp
diff --git
a/testThread.cpp
b/testThread.cpp
index
e8d0477
..
e3087e1
100644
(file)
--- a/
testThread.cpp
+++ b/
testThread.cpp
@@
-5,7
+5,7
@@
#include <QDateTime>
TestThread::TestThread(QObject *parent):QThread(parent){
colore=0;
#include <QDateTime>
TestThread::TestThread(QObject *parent):QThread(parent){
colore=0;
- attendiInputUtente=false;
+
index=0;
_score=0;
index=0;
_score=0;
@@
-16,8
+16,9
@@
TestThread::~TestThread(){
}
void TestThread::run(){
}
void TestThread::run(){
+ sleep(1);
while(true){
while(true){
-
+ mutex.lock();
qsrand(QDateTime::currentDateTime().toTime_t());
sequenza.append(qrand()%9);
int i=0;
qsrand(QDateTime::currentDateTime().toTime_t());
sequenza.append(qrand()%9);
int i=0;
@@
-28,18
+29,17
@@
void TestThread::run(){
{
emit generate(sequenza.at(i));
qDebug()<<sequenza.at(i);
{
emit generate(sequenza.at(i));
qDebug()<<sequenza.at(i);
- msleep(500 - (_score*5));
+ msleep(500 - (_score*2));
emit generate(sequenza.at(i));
emit generate(sequenza.at(i));
- msleep(500 - (_score*5));
+ msleep(500 - (_score*2));
i++;
}
i=0;
i++;
}
i=0;
- attendiInputUtente=true;
emit enableInterface();
emit enableInterface();
+ attendiInputUtente.wait(&mutex);
+
+ mutex.unlock();
- while(attendiInputUtente){
- msleep(1);
- }
}
}
@@
-47,31
+47,32
@@
void TestThread::run(){
void TestThread::updateCaption(int inputUser){
void TestThread::updateCaption(int inputUser){
- if(attendiInputUtente){
+
if(sequenza.at(index)==inputUser)
{
index++;
_score++;
if(sequenza.at(index)==inputUser)
{
index++;
_score++;
-
+ emit score(_score);
if(index==sequenza.size()){
if(index==sequenza.size()){
- attendiInputUtente=false;
+ sleep(1);
+ attendiInputUtente.wakeAll();
index=0;
}
}
else{
index=0;
}
}
else{
- emit score(_score);
+ emit exit(_score);
_score=0;
sequenza.clear();
index=0;
_score=0;
sequenza.clear();
index=0;
- attendiInputUtente=true;
+ attendiInputUtente.wakeAll();
}
}
- }
+
}
void TestThread::genera()
{
}
void TestThread::genera()
{
- qDebug()<<"Init Emission";
- attendiInputUtente=false;
+
+ attendiInputUtente.wakeAll();
}
}