Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Embedded QT: How to Fix the Error "QWidget::paintEngine: Should no longer be called"



  • Hi everyone,

    Now I am trying to make the embedded QT GUI run on the Ambarella CV25 board. I had cross-compiled the QT 5.12.3 everywhere and compiled a simple qt example. The cross compiler is Ambarella CV25 linaro-aarch64-2018.08-gcc8.2/bin/aarch64-linux-gnu-xxx.

    When I download the qt lib and example to the board, I encountered the following issue:

    ./my_second_example -platform linuxfb
    QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed
    QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed
    QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::setPen: Painter not active
    QPainter::setBrush: Painter not active
    QPainter::drawRects: Painter not active
    debug paintEvent(): QPaintDevice  0x7fe05f0d78
    debug paintEvent():  painter.isActive  false
    debug paintEvent(): QPaintEngine  0x0
    .....
    

    Could anyone know how to fix the issue? I searched the web, but all posts I found had either no answer to them, or give suggestion that paint under the paintEvent function.
    Thanks a million!

    My Code:

    • PaintTest.h:
    #ifndef PAINTTEST_H
    #define PAINTTEST_H
    
    #include <QWidget>
    #include <QLabel>
    #include <QPainter>
    class PaintTest : public QWidget
    {
        Q_OBJECT
    
    public:
         explicit PaintTest(QWidget *parent = nullptr);
         void paintEvent(QPaintEvent *);
    };
    #endif // PAINTTEST_H
    
    • PaintTest.cpp
    #include "PaintTest.h"
    #include <QLabel>
    #include <QEvent>
    #include <QDebug>
    
    PaintTest::PaintTest(QWidget *parent) :
        QWidget(parent)
    {
    
    }
    
    void PaintTest::paintEvent(QPaintEvent *) {
         QPainter painter(this);
    
         painter.begin(this);
         painter.setPen(Qt::gray);
         painter.setBrush(Qt::green);
         painter.drawRect(10, 20, 50, 50);
         //painter.drawText(rect(),Qt::AlignCenter,tr("Draganddropfile(s)here"));
    
         qDebug()<<"debug paintEvent(): QPaintDevice " << painter.device();
         qDebug()<<"debug paintEvent(): painter.isActive " << painter.isActive();
         qDebug()<<"debug paintEvent(): QPaintEngine " << painter.paintEngine();
         painter.end();
    }
    
    • main.cpp
    #include <QApplication>
    #include "PaintTest.h"
    
    int main(int argc,char* argv[])
    {
         QApplication a(argc, argv);
    
        PaintTest pt;
         pt.show();
    
         return a.exec();
    }
    

    And I will also provide the embedded qt configure parameters when I cross-compiled the qt everywhere:

    ../qt-everywhere-src-5.12.3/configure -v -prefix /home/andy/Amb/cv2x_linux_sdk_2.5/workspace/build_qt/output -release -opensource -confirm-license -no-accessibility -make libs -xplatform linux-aarch64-gnu-g++ -optimized-qmake -pch -qt-zlib -no-opengl -no-sse2 -no-openssl -no-cups -no-glib -no-pkg-config -no-separate-debug-info -tslib -I/home/andy/Amb/cv2x_linux_sdk_2.5/ambarella/prebuild/third-party/armv8-a/tslib/include -L/home/andy/Amb/cv2x_linux_sdk_2.5/ambarella/prebuild/third-party/armv8-a/tslib/usr/lib -skip qtdeclarative
    

    The CV25 platform not support opengl, so I disable the eglfs, use the linuxfb.

    Thanks again!!!
    andy


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you pass your instance when creating the painter, there is no need to call begin. I'll start with that.



  • @SGaist said in Embedded QT: How to Fix the Error "QWidget::paintEngine: Should no longer be called":

    Since you pass your instance when creating the painter, there is no need to call begin. I'll start with that.

    Thanks for your reply! yes, there is no need to call begin and end. It is the same result when not call begin.


  • Lifetime Qt Champion

    What device are you running that on ?
    Does showing a simple widget work correctly ?

    [edit: fixed missing word SGaist]



  • @SGaist Hi, the device is the ambarella CV25 chip Develop Board. It run an embedded linux kernel, the frame buffer device in linux kernel also work well. There were no samples in its SDK. I just tried to run this simple sample but failed.


  • Lifetime Qt Champion

    Sorry, I just saw there was a missing word in my phrase and fixed it.

    What do you get if you just show a normal unmodified QWidget object ?


Log in to reply