Asynchronous drawing problems

  • I have one thread that reads image data from an external API. This image data I want to draw in an Qt application. I have created a widget to draw the image. The thread calls MyWidget::setPicture. However I get lots of strange X server errors, so I'm guessing something is not threads safe. Any tips on how to do this?

    class MyWidget : public QWidget
    MyWidget(QWidget *parent = 0);

    QPixmap pixmap;
    void setPicture(QImage);

    void paintEvent(QPaintEvent *event);


    void MyWidget::paintEvent(QPaintEvent */event/) {
    QPainter painter(this);

    void MyWidget::setPicture(QImage i){


  • Why do you call @qApp->processEvents();@? And can you show code block where thread calls setPicture

  • You have to call the QWidget methods inside the main thread. I think that is your problem. If MyWidget::setPicture is a slot, you can call it by QObject::invokeMethod(...Qt::QueuedConnection) to call from your thread to the main thread.

Log in to reply

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