Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Asynchronous drawing problems
Forum Updated to NodeBB v4.3 + New Features

Asynchronous drawing problems

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pibben
    wrote on last edited by
    #1

    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
    {
    Q_OBJECT
    public:
    MyWidget(QWidget *parent = 0);
    ~MyWidget();

    QPixmap pixmap;
    void setPicture(QImage);
    

    protected:
    void paintEvent(QPaintEvent *event);

    };
    @

    @
    void MyWidget::paintEvent(QPaintEvent */event/) {
    QPainter painter(this);
    painter.drawPixmap(this->rect(),pixmap);
    }

    void MyWidget::setPicture(QImage i){
    pixmap=QPixmap::fromImage(i);
    update();
    qApp->processEvents();
    }

    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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.

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved