September 7, 2011

sushmars sushmars
Lab Rat
13 posts

Qt + in porting + i got error QWidget::paintEngine: Should no longer be called QPainter::begin: Paint device returned engine == 0, type: 1

 

hi,
In my code i use to draw a real time graph outside paintEvent by setting property WA_PaintOutsidePaintEvent to true for qframe. It is plotting properly in my linux desktop as it is having x11. when i ran the same app in my arm based processor for which we have ported qt, i am getting error
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1

As my arm environment is not having x11,Is this is the problem to draw outside paint event.

5 replies

September 7, 2011

peppe peppe
Ant Farmer
1028 posts

Well: don’t do that. Paint on a QImage / QPixmap buffer and schedule a repaint, then just blit the buffer.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

September 7, 2011

sushmars sushmars
Lab Rat
13 posts

Then i need to use paintEvent function because repaint / update will call paintEvent function.
Any other solution to draw outside paintEvent function because in my application there are 15 different graphs. some page will display 4 graphs at a time on a same gui-page depending on real time value.

Thanks for reply

September 7, 2011

peppe peppe
Ant Farmer
1028 posts

Yes, but the paintEvent will be easy to code (just blit the buffer you prepared, i.e.

  1. QPainter p(this);
  2. p.drawPixmap(buffer);

. And in the other places where you used to paint directly on the widget, just open the painter on that buffer instead. I know it’s a hack, but painting outside paint events is definitely something you shouldn’t do in the first place.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

September 7, 2011

Gerolf Gerolf
Robot Herder
3252 posts

Hi sushmars,

if you are not using X11, which painting system do you use? Qt embedded with framebuffer? then perhaps a QDirectPainter [doc.qt.nokia.com] could help, as you xcan access the framebuffer also outside the paint event. But then you loos Qt’s double buffer features…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 7, 2011

sushmars sushmars
Lab Rat
13 posts

Here is a piece of code which displays 2 graphs at a time Which is called by 2 threads simultaneously.

  1. QPainter *Dys_ecgpainter;
  2. QPainter *Dys_Balpainter;

in init function i declare those 2 painters

  1. {
  2. Dys_ecgpainter= new QPainter;
  3. ansiscopeMainWindow->ui->DysAutonomia_Test_ECG_frame->setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
  4. Dys_ecgpainter->begin((QWidget*)ansiscopeMainWindow->ui->DysAutonomia_Test_ECG_frame);
  5. Dys_ecgpainter->drawRect(0,0,235,80);
  6.  
  7. Dys_Balpainter = new QPainter;
  8. ansiscopeMainWindow->ui->DysAutonomia_Test_balANS_frame->setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
  9. Dys_Balpainter->begin( (QWidget*)ansiscopeMainWindow->ui->DysAutonomia_Test_balANS_frame);
  10. Dys_Balpainter->drawRect(0,0,235,80);
  11.  
  12. }

Dys_DrawECG function is called from ECG thread which plots ecg on a qframe

  1. void Dys_DrawECG(int data)
  2. {
  3.      Dys_ecgpainter->drawLine(Dys_ECGgraph.lastplot.X,Dys_ECGgraph.lastplot.Y,Dys_ECGgraph.currentplot.X,Dys_ECGgraph.currentplot.Y);
  4.  
  5.  
  6.     if(Dys_ECGgraph.currentplot.X >= Dys_ECGgraph.rightbottom.X)
  7.     {
  8.         Dys_ECGgraph.currentplot.X = 0;
  9.         Dys_ecgpainter->fillRect(0,0,235,80,Qt::white);
  10.         //qWarning("\nAfter reaching end of frame 200\n");
  11.  
  12.     }
  13.  
  14.     Dys_ECGgraph.lastplot.X=Dys_ECGgraph.currentplot.X;
  15.     Dys_ECGgraph.lastplot.Y=Dys_ECGgraph.currentplot.Y;
  16.  
  17. }

Dys_DrawbalANS function is called from BalANS thread which plots balANS on a qframe

  1. void Dys_DrawbalANS(POINT *Dys_points)
  2. {
  3.  
  4.  
  5.     int i;
  6.     int firsttime=1;
  7.  
  8.     float x,y;
  9.     int Xvalue ,Yvalue ;
  10.     int Xpos, Ypos;
  11.     int balCurrentPlotX, balCurrentPlotY, balLastPlotX, balLastPlotY;
  12.     balCurrentPlotX = 0;
  13.     balCurrentPlotY = 0;
  14.     balLastPlotX = 0;
  15.     balLastPlotY = 0;
  16.  
  17.    
  18.  
  19.  
  20.      Dys_Balpainter->fillRect(0,0,235,80,Qt::white);
  21.      Dys_Balpainter->drawLine(117,0,117,20);
  22.      Dys_Balpainter->drawLine(60,0,60,10);
  23.      Dys_Balpainter->drawLine(174,0,174,10);
  24.  
  25.      Dys_Balpainter->drawLine(0,40,20,40);
  26.      Dys_Balpainter->drawLine(0,20,10,20);
  27.      Dys_Balpainter->drawLine(0,60,10,60);
  28.  
  29.     firsttime =1;
  30.     for(i = 0; i< 312; i++)
  31.     {
  32.  
  33.        
  34.  
  35.         if(firsttime)
  36.         {
  37.             firsttime=0;
  38.             // Balpainter->moveTo(Xpos,Ypos);  //Pen Position
  39.             Dys_Balpainter->drawPoint(balCurrentPlotX,balCurrentPlotX);
  40.  
  41.         }
  42.         else
  43.         {   Dys_Balpainter->drawLine(balCurrentPlotX, balCurrentPlotY, balLastPlotX, balLastPlotY);
  44.         }
  45.        
  46.         balLastPlotX = balCurrentPlotX;
  47.         balLastPlotY = balCurrentPlotY;
  48.     }
  49. }

EDIT: please use @-tags for code highlighting, Gerolf

 
  ‹‹ Strange things with QSslSocket (Qt 4.7.4)      QGraphicsItem::setOpacity and QGraphicsOpacityEffect ››

You must log in to post a reply. Not a member yet? Register here!