whether it is possible to call functions using threads without using multi-thread or class threads
-
Is it possible to call a function that contains a process loop and change the label using only one main class without creating multi-threads?
here is my code examplevoid MainWindow::Process() { while (2) { if (status) { ui->label->setText("Process.."); // my process.... } else { ui->label->setText("Process Failed"); } } }
-
Hi,
What is that "process" ?
Note that with your infinite loop you will be blocking Qt's event loop.
-
@SGaist said in whether it is possible to call functions using threads without using multi-thread or class threads:
Apa "proses" itu?
that's just an example of my original code, but that's part of the other code, but the problem is when I call the function using a regular thread an error occurs "QObject::killTimer: Timers cannot be stopped from another thread" and this is the thread I used to call the Process function
std::thread thread(&MainWindow::Process, this); thread.detach();
-
You cannot call GUI related function from a different thread.
-
@Blackzero said in whether it is possible to call functions using threads without using multi-thread or class threads:
So you mean I can't call GUI functions in threads not from qt's built-in QThread
That's exactly what @SGaist wrote.
-
@Blackzero
It doesn't actually matter whether you useQThread
,std::thread
or anything else: you are not allowed to directly access any Qt GUI functions/variables etc. from any thread other than the original, main thread of your Qt application. Qt GUI operations are not multithreaded. At best you can send signals from secondary threads which the main thread has put a slot on, so that it is the main thread which accesses the GUI stuff "on behalf of" whatever the secondary thread reports.