Per risolvere alcuni problemi relativi al thread sono state agginte
le QMutex e le QWaitCondition
# Project created by QtCreator 2010-02-18T12:16:41
# -------------------------------------------------
QT += svg
# Project created by QtCreator 2010-02-18T12:16:41
# -------------------------------------------------
QT += svg
TEMPLATE = app
RESOURCES = qled.qrc
SOURCES += main.cpp \
TEMPLATE = app
RESOURCES = qled.qrc
SOURCES += main.cpp \
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QMainWindow(parent),
ui(new Ui::MainWindow)
{
- bestScore=0;
- readSettings();
+ bestScore=0;
+ readSettings();
ui->setupUi(this);
statusLed = new QLed(ui->verticalLayoutWidget);
ui->horizontalLayout_4->insertWidget(0,statusLed);
ui->setupUi(this);
statusLed = new QLed(ui->verticalLayoutWidget);
ui->horizontalLayout_4->insertWidget(0,statusLed);
sscore.append("\n Best score: ");
sscore.append(QString::number(bestScore));
QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
sscore.append("\n Best score: ");
sscore.append(QString::number(bestScore));
QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
- //tread.genera();
- exit(0);
+ bestScore=0;
+ readSettings();
+ tread.genera();
+
+ //exit(0);
}
void MainWindow::disableAll(){
}
void MainWindow::disableAll(){
#include <QDateTime>
TestThread::TestThread(QObject *parent):QThread(parent){
colore=0;
#include <QDateTime>
TestThread::TestThread(QObject *parent):QThread(parent){
colore=0;
- attendiInputUtente=false;
void TestThread::run(){
sleep(1);
while(true){
void TestThread::run(){
sleep(1);
while(true){
qsrand(QDateTime::currentDateTime().toTime_t());
sequenza.append(qrand()%9);
int i=0;
qsrand(QDateTime::currentDateTime().toTime_t());
sequenza.append(qrand()%9);
int i=0;
- attendiInputUtente=true;
+ attendiInputUtente.wait(&mutex);
+
+ mutex.unlock();
- while(attendiInputUtente){
- msleep(1);
- }
void TestThread::updateCaption(int inputUser){
void TestThread::updateCaption(int inputUser){
- if(attendiInputUtente){
if(sequenza.at(index)==inputUser)
{
if(sequenza.at(index)==inputUser)
{
emit score(_score);
if(index==sequenza.size()){
sleep(1);
emit score(_score);
if(index==sequenza.size()){
sleep(1);
- attendiInputUtente=false;
+ attendiInputUtente.wakeAll();
_score=0;
sequenza.clear();
index=0;
_score=0;
sequenza.clear();
index=0;
- attendiInputUtente=true;
+ attendiInputUtente.wakeAll();
}
void TestThread::genera()
{
}
void TestThread::genera()
{
- attendiInputUtente=false;
+ attendiInputUtente.wakeAll();
#define TESTTHREAD_H
#include <QThread>
#define TESTTHREAD_H
#include <QThread>
+#include <QWaitCondition>
+#include <QMutex>
class TestThread : public QThread
class TestThread : public QThread
+ QWaitCondition attendiInputUtente;
int colore;
int index;
int _score;
int colore;
int index;
int _score;
- bool attendiInputUtente;
QList<int> sequenza;
};
#endif // TESTTHREAD_H
QList<int> sequenza;
};
#endif // TESTTHREAD_H