André Puel
André Puel

Reputation: 9179

Qt Events after a long routine freezes my application for a while

So, I have a single-threaded application which loads data from a set of file:

QStringList qFiles = QFileDialog::getOpenFileNames(
    this,
    "Choose Image Files",
    "",
    "Dicom Files(*.dcm);;All Files(*)"
);

After that I invoke a library which will parse the set of files, since the library invokes OpenGL functions I may not create a new thread for this processing. Once this processing is done I noticed my application froze for a while.

Using GDB I noticed my Qt Application buffered a lot of Events while the library processed the set of files and then it is processing these events.

I may not invoke QApplication::instance()->processEvents() inside the libary, because it doesnt know Qt(project decision).

Is there way to discard these events? Or is there any other solution to keep my application from freezing?

Upvotes: 1

Views: 236

Answers (1)

Will Bickford
Will Bickford

Reputation: 5386

Move OpenGL Rendering to a Worker Thread

If possible, move your OpenGL rendering to a separate thread. Then you can call your library functions there and not worry about them blocking the event queue.

You should be able to devote your framebuffer to the worker thread and communicate with it using signals and slots just fine.

Alternative: Implement Progress Callbacks

Alternatively you could see if the library has any callbacks. If you have source available, you could implement your own during long-running operations.

Upvotes: 1

Related Questions