-1

I am currently working on a Java project using Qt Jambi for the UI. I am doing some calculations in a thread different from the UI thread and I would like to update the UI to indicate the progress.

It is clear that UI updates can only be done on the UI thread and since the computation thread is not the UI thread, I cannot perform updates on the UI from there (trying that consequently results in the QObject used from outside its own thread error).

So, how can I call my updateUI() method on the UI thread?

Björn Marschollek
  • 9,899
  • 9
  • 40
  • 66

2 Answers2

6

I just found a solution myself. QApplication provides the invokeLater method to perform operations on the UI thread:

QApplication.invokeLater(new Runnable() {
    @Override
    public void run() {
        updateUI();
    }
});
Björn Marschollek
  • 9,899
  • 9
  • 40
  • 66
0

I have given a similar answer before but I could not find it. So I will just repeat what I have said before.

You need to use signal/slot mechanism of qt to make communication happen between main thread with a worker thread.

Checkout the Mandelbrot example.

I hope this helps.

O.C.
  • 6,711
  • 1
  • 25
  • 26