PDA

View Full Version : Qtimer effect on GUI problem



anh5kor
1st December 2014, 15:16
Hello,
I am developing a GUI where i am using QTimer class for updating the GUI for every 100 millisecond.


connect(timer,SIGNAL(timeout()),this,SLOT(updategu i()));
timer->start(100);

The code works fine .It update in the GUI but my GUI get hangs for some millisecond.i.e when I am changing the tab it is taking some time.
Once I remove the timer from my class my GUI works fine,I can move GUI with no delay .

can anyone provide me some better idea where I update my GUI every 100 millisecond and I don't get any GUI movement delay

Lesiok
1st December 2014, 15:40
Update GUI every millisecond makes no sense.
First : with monitor refresh frequency 70 Hz a new picture is displayed every 13,3 ms.
Second : the human eye recognizes about 25 images per second (this is one picture in 40 ms).

anh5kor
1st December 2014, 16:07
ok its not every its 100 millisecond

wysota
1st December 2014, 18:25
ok its not every its 100 millisecond

Still it is probably way to often. What does updategui() actually do?

anh5kor
2nd December 2014, 10:41
GUI is connected with a hardware internally where it request the hardware every 100 millisecond for the updated value.
The value need to be show on GUI.
updategui() is a slot which implement the above process.

Lesiok
2nd December 2014, 11:15
Show us this slot.

anh5kor
2nd December 2014, 13:47
The slot I created you can see on above post.
If you asking about the function updategui().


bool updategui()
{
bOK = m_D2xxport->Read(answer_p);
palette->setColor(QPalette::Text,Qt::green);
ui.le_status->setPalette(*palette);
ui.le_status->setText("correct answer.");
Displayvalue(bOK );
m_bConnected = false;
m_D2xxport->Close();
return false;
}

wysota
2nd December 2014, 15:08
Is Read() a blocking call? How long does it execute?

Lesiok
2nd December 2014, 15:12
Is the m_D2xxport->Read() blocking IO ?

anh5kor
2nd December 2014, 16:55
Read() function consist of some command which send to hardware.
And hardware reply same with some hexadecimal value.Its just like a serial port communication.

wysota
2nd December 2014, 21:44
Read() function consist of some command which send to hardware.
And hardware reply same with some hexadecimal value.Its just like a serial port communication.

How long does it take? You can estimate it with QElapsedTimer.

Lesiok
3rd December 2014, 09:24
Read() function consist of some command which send to hardware.
And hardware reply same with some hexadecimal value.Its just like a serial port communication.
And this is the source of your problem. Probably the reading takes several milliseconds.

anh5kor
3rd December 2014, 10:28
yes reading takes some 1000 millisecond.
whether the upategui() time and reading time should match I don't have any idea.
Can you let me know some solution or some approach

Lesiok
3rd December 2014, 10:45
You can move reading process to another thread. Update GUI should be initiated by some signal from this thread not with QTimer.

anh5kor
4th December 2014, 13:57
Thanks for the suggestion I have implemented and it's working fine