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.



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



  • 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



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

    @
    QPainter p(this);
    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.



  • Hi sushmars,

    if you are not using X11, which painting system do you use? Qt embedded with framebuffer? then perhaps a "QDirectPainter":http://doc.qt.nokia.com/latest/qdirectpainter.html could help, as you xcan access the framebuffer also outside the paint event. But then you loos Qt's double buffer features...



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

    @
    QPainter *Dys_ecgpainter;
    QPainter *Dys_Balpainter;
    @

    in init function i declare those 2 painters

    @
    {
    Dys_ecgpainter= new QPainter;
    ansiscopeMainWindow->ui->DysAutonomia_Test_ECG_frame->setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
    Dys_ecgpainter->begin((QWidget*)ansiscopeMainWindow->ui->DysAutonomia_Test_ECG_frame);
    Dys_ecgpainter->drawRect(0,0,235,80);

    Dys_Balpainter = new QPainter;
    ansiscopeMainWindow->ui->DysAutonomia_Test_balANS_frame->setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
    Dys_Balpainter->begin( (QWidget*)ansiscopeMainWindow->ui->DysAutonomia_Test_balANS_frame);
    Dys_Balpainter->drawRect(0,0,235,80);

    }
    @

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

    @
    void Dys_DrawECG(int data)
    {
    Dys_ecgpainter->drawLine(Dys_ECGgraph.lastplot.X,Dys_ECGgraph.lastplot.Y,Dys_ECGgraph.currentplot.X,Dys_ECGgraph.currentplot.Y);

    if(Dys_ECGgraph.currentplot.X >= Dys_ECGgraph.rightbottom.X)
    {
        Dys_ECGgraph.currentplot.X = 0;
        Dys_ecgpainter->fillRect(0,0,235,80,Qt::white);
        //qWarning("\nAfter reaching end of frame 200\n");
    
    }
    
    Dys_ECGgraph.lastplot.X=Dys_ECGgraph.currentplot.X;
    Dys_ECGgraph.lastplot.Y=Dys_ECGgraph.currentplot.Y;
    

    }
    @

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

    @
    void Dys_DrawbalANS(POINT *Dys_points)
    {

    int i;
    int firsttime=1;
    
    float x,y;
    int Xvalue ,Yvalue ;
    int Xpos, Ypos;
    int balCurrentPlotX, balCurrentPlotY, balLastPlotX, balLastPlotY;
    balCurrentPlotX = 0;
    balCurrentPlotY = 0;
    balLastPlotX = 0;
    balLastPlotY = 0;
    
    
    
    
     Dys_Balpainter->fillRect(0,0,235,80,Qt::white);
     Dys_Balpainter->drawLine(117,0,117,20);
     Dys_Balpainter->drawLine(60,0,60,10);
     Dys_Balpainter->drawLine(174,0,174,10);
    
     Dys_Balpainter->drawLine(0,40,20,40);
     Dys_Balpainter->drawLine(0,20,10,20);
     Dys_Balpainter->drawLine(0,60,10,60);
    
    firsttime =1;
    for(i = 0; i< 312; i++)
    {
    
        
    
        if(firsttime)
        {
            firsttime=0;
            // Balpainter->moveTo(Xpos,Ypos);  //Pen Position
            Dys_Balpainter->drawPoint(balCurrentPlotX,balCurrentPlotX);
    
        }
        else
        {   Dys_Balpainter->drawLine(balCurrentPlotX, balCurrentPlotY, balLastPlotX, balLastPlotY);
        }
        
        balLastPlotX = balCurrentPlotX;
        balLastPlotY = balCurrentPlotY;
    }
    

    }
    @

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.