3

I have a problem with Paintevent in Qt. Paintevent thread is utilizing almost all amount of CPU when started.

Code in constructor of my main widget.

Display_dialog::Display_dialog(QWidget *parent):QDialog(parent),
ui(new Ui::Display_dialog)
{
     ui->setupUi(this);
     pRedraw_Timer = new QTimer(this);
     connect( pRedraw_Timer, SIGNAL(timeout()), this, SLOT(update()));
     pRedraw_Timer->start( 15 );
}

And in my paintevent,

 void MyDialog::paintEvent(QPaintEvent *event)
 {
 }

Nothing at all in Paintevent!!!But running this piece of code consumes 100% of CPU [CPU is Single core 1 Ghz Processor].

And when I stop(pRedraw_Timer->stop()) this pRedraw_Timer which calls update, for ex: On a button click the usage comes down to 1% or under 10% almost instantly!!!!

My requirement is plotting a graph depending upon input from serial port. So i need to constantly update the view using update. But while plotting, any interrupt(high priority) seems to disturb the plotting, as cpu switches for handling the interrupt. After handling interrupt, plotting comes back to normal. My question is how and why is this paintevent thread consuming 100% CPU even if its not doing anything at all. How can I change this Scenario?

EDIT(for kuba ober): Well there are several other functions and slots. But nothing is invoked unless I call it or Trigger a Signal. I am not doing anything at all. Just after running the program, it consumes all cpu. Remember only constructor of main dialog is called.

4

0 回答 0