lamp
26th February 2012, 18:05
Hello
I create three Threads with QtConcurrent :
1- First Thread connect to devise (with Qtimer interval 0.05 seconds and set AvailableValue = 1 if 20 value is reading )
2- Second Thread Control AvailableValue == 1 (in per seconds) and draw graph (qpainter event with Qtimer interval 1 seconds)
(Value saving in qlist )
2- Third Thread (in 5 minut) save value to mysql db (qpainter event with Qtimer interval 300 seconds)
problem
run Second Thread Or Third Thread ,Occurrence delay in First Thread
(if use mouse event in Second Thread, further delay)
How to Resolve this problem?
Code:
Read_timer = new QTimer();
draw_timer = new QTimer();
FirstThread = new QFuture<void>;
watcher3 = new QFutureWatcher<void>;
* FirstThread = QtConcurrent::run(this,&MainWindow::Devs);
watcher3->setFuture(*FirsThread);
SecondThread = new QFuture<void>;
watcher2 = new QFutureWatcher<void>;
*SecondThread = QtConcurrent::run(this,&MainWindow::Graph);
watcher2->setFuture(*SecondThread);
ThirdThread = new QFuture<void>;
watcher1 = new QFutureWatcher<void>;
*ThirdThread = QtConcurrent::run(this,&MainWindow::Save);
watcher1->setFuture(*ThirdThread);
void MainWindow::Devs()
{
connect(Read_timer,SIGNAL(timeout()), this, SLOT(Read_Devs()));
Read_timer->setInterval(50);
Read_timer->start();
}
void MainWindow::Read_Devs()
{
{
adv0->adv1716_read(values_float);
adv1->adv1716_read(values_float);
readconter++;
}
if(readconter==20)
{
tmpValues_float = values_float;
isAvalaibelValus = 1;
readconter=0;
values_float.clear();
}
}
void MainWindow::Graph ()
{
connect(CheckTask_timer,SIGNAL(timeout()), this, SLOT(draw()));
draw_timer->setInterval(1000);
draw_timer->start();
}
void MainWindow::Save ()
{
connect(CheckTask_timer,SIGNAL(timeout()), this, SLOT(Save_mysql()));
draw_timer->setInterval(300000);
draw_timer->start();
}
I create three Threads with QtConcurrent :
1- First Thread connect to devise (with Qtimer interval 0.05 seconds and set AvailableValue = 1 if 20 value is reading )
2- Second Thread Control AvailableValue == 1 (in per seconds) and draw graph (qpainter event with Qtimer interval 1 seconds)
(Value saving in qlist )
2- Third Thread (in 5 minut) save value to mysql db (qpainter event with Qtimer interval 300 seconds)
problem
run Second Thread Or Third Thread ,Occurrence delay in First Thread
(if use mouse event in Second Thread, further delay)
How to Resolve this problem?
Code:
Read_timer = new QTimer();
draw_timer = new QTimer();
FirstThread = new QFuture<void>;
watcher3 = new QFutureWatcher<void>;
* FirstThread = QtConcurrent::run(this,&MainWindow::Devs);
watcher3->setFuture(*FirsThread);
SecondThread = new QFuture<void>;
watcher2 = new QFutureWatcher<void>;
*SecondThread = QtConcurrent::run(this,&MainWindow::Graph);
watcher2->setFuture(*SecondThread);
ThirdThread = new QFuture<void>;
watcher1 = new QFutureWatcher<void>;
*ThirdThread = QtConcurrent::run(this,&MainWindow::Save);
watcher1->setFuture(*ThirdThread);
void MainWindow::Devs()
{
connect(Read_timer,SIGNAL(timeout()), this, SLOT(Read_Devs()));
Read_timer->setInterval(50);
Read_timer->start();
}
void MainWindow::Read_Devs()
{
{
adv0->adv1716_read(values_float);
adv1->adv1716_read(values_float);
readconter++;
}
if(readconter==20)
{
tmpValues_float = values_float;
isAvalaibelValus = 1;
readconter=0;
values_float.clear();
}
}
void MainWindow::Graph ()
{
connect(CheckTask_timer,SIGNAL(timeout()), this, SLOT(draw()));
draw_timer->setInterval(1000);
draw_timer->start();
}
void MainWindow::Save ()
{
connect(CheckTask_timer,SIGNAL(timeout()), this, SLOT(Save_mysql()));
draw_timer->setInterval(300000);
draw_timer->start();
}