Hi,
I'm trying to load a C++ object from qml, but it freezes the UI. Here's what I tried/understood:
Method One: I have a simple qml button, and when I click it, I directly invoke the C++ object's load slot. Loading takes a couple of seconds, during which the UI is frozen. It should be frozen; the thread that's running the UI is now processing my C++ load function.
Method Two: I have a simple qml button, and when I click it, I directly invoke the C++ object's special placeholder function. All this function does is emit a signal from the C++ object, which is connected to the C++ object's Load slot. Again, the UI freezes for a couple of seconds. I thought that the C++ object lies in a different thread, the UI thread should only emit the signal, but this doesn't happen... the UI thread executes the Load slot too, since it freezes up for the same time as Method One.
Method Three: Tried to set it up so that the QML emits a signal to the C++ object instead of invoking a C++ object slot directly. Problem is that my QML Element lies inside a QML Loader{} from another QML file. I tried, but I couldn't use QObject's findChild() method to find the specific object I need to receive the signal from.
When I check the running process with gdb, I see that two threads are started up. I thought one thread was for the QML view, and the other for the rest of the app. Is this wrong? Do I need a third thread?
edit: Adding a thread solved this problem.
main.cpp: contains my declarative view and main object
I throw my main object in another thread, and everything works as it should![]()
Bookmarks