GUI is Freeze When Start QtConcurrent::run Process
-
Hello Qt Experts And my friends
Currently i am facing GUI freezing problem in my project
My Application GUI is Freeze when i start multiple
QtConcurrent::run
processfor example i want to run 2 or 3 methods parallelly
or in this methods i am doing some looping code thigs or some processing or etc then when i Try To Display result in my GUI Controls likeQLabel
OrQFrame
or etc.. that time my GUI Is freezed But Backend processing is runningMy All Background processing Is Work Correctly like
QTimer
Value But GUI is freezedAnd Other things is when i Clicked on my other Controls like
QPushButton
that time My Application is Keep going Normally with All GUI ControlsPlease Help me for find out the solution Or If You have Solution or Any idea About My Problem then Please Drop Your idea or solution here....
Thank You So Much
-
Hi,
Please show the code where you are using QtCouncurrent.
If something freezes, you have likely used a method to wait on the result of your computation.
-
Hi,
Please show the code where you are using QtCouncurrent.
If something freezes, you have likely used a method to wait on the result of your computation.
Thanks For Reply
void MainWindow::StartFunctions() { if(!future_1.isRunning()) future_1 = QtConcurrent::run(&pool, this, &MainWindow::Function_1); if(!future_2 .isRunning()) future_2 = QtConcurrent::run(&pool, this, &MainWindow::Function_2); } void MainWindow::Function_1() { while(IS_Thread_1_Start == true) { ///// My Code } } void MainWindow::Function_2() { while(IS_Thread_2_Start == true) { ///// My Code } } void MainWindow::on_BtnStart_clicked() //// START { StartFunctions(); } void MainWindow::on_BtnStop_clicked() //// STOP { IS_Thread_1_Start = false; IS_Thread_2_Start = false; }
-
Why are you implementing such blocking loops within your MainWindow code ?
-
Thanks For Reply
because I want to call my MainWindow Class functions in my Threads Functions
Like this::
void MainWindow::Function_1_Process() { ui->Label_1->setText(QString::number(Number_1)) /// Here Number_1 Is My Windows Class Member } void MainWindow::Function_2_Process() { ui->Label_2->setText(QString::number(Number_2)) /// Here Number_2 Is My Windows Class Member } void MainWindow::Function_1() { while(IS_Thread_1_Start == true) { Function_1_Process(); Number_1 += 1; } } void MainWindow::Function_2() { while(IS_Thread_2_Start == true) { Function_2_Process(); Number_1 += 1; } }
-
Thanks For Reply
because I want to call my MainWindow Class functions in my Threads Functions
Like this::
void MainWindow::Function_1_Process() { ui->Label_1->setText(QString::number(Number_1)) /// Here Number_1 Is My Windows Class Member } void MainWindow::Function_2_Process() { ui->Label_2->setText(QString::number(Number_2)) /// Here Number_2 Is My Windows Class Member } void MainWindow::Function_1() { while(IS_Thread_1_Start == true) { Function_1_Process(); Number_1 += 1; } } void MainWindow::Function_2() { while(IS_Thread_2_Start == true) { Function_2_Process(); Number_1 += 1; } }
@Ketan__Patel__0011 said in GUI is Freeze When Start QtConcurrent::run Process:
because I want to call my MainWindow Class functions in my Threads Functions
Never do this directly! Only GUI thread is allowed to change the UI (access UI related objects)!
Emit a signal from the other thread and connect that signal to a slot in MainWindow. -
@Ketan__Patel__0011 said in GUI is Freeze When Start QtConcurrent::run Process:
because I want to call my MainWindow Class functions in my Threads Functions
Never do this directly! Only GUI thread is allowed to change the UI (access UI related objects)!
Emit a signal from the other thread and connect that signal to a slot in MainWindow.@jsulm
Thanks For ReplyI Understand
but now is there any other way to help for this problem ? -
@jsulm
Thanks For ReplyI Understand
but now is there any other way to help for this problem ?@Ketan__Patel__0011 What is wrong with my suggestion?
You could also use https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod with Qt::QueuedConnection -
@Ketan__Patel__0011 What is wrong with my suggestion?
You could also use https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod with Qt::QueuedConnectionYour Suggestion Is Not Wrong
-
Your Suggestion Is Not Wrong
This post is deleted! -
Your Suggestion Is Not Wrong
@Ketan__Patel__0011 OK. Then take a look at the alternative I proposed.