Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved GUI is Freeze When Start QtConcurrent::run Process

    General and Desktop
    3
    11
    346
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ketan__Patel__0011
      Ketan__Patel__0011 last edited by

      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 process

      for 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 like QLabel Or QFrame or etc.. that time my GUI Is freezed But Backend processing is running

      My All Background processing Is Work Correctly like QTimer Value But GUI is freezed

      And Other things is when i Clicked on my other Controls like QPushButton that time My Application is Keep going Normally with All GUI Controls

      Please 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

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Ketan__Patel__0011 1 Reply Last reply Reply Quote 1
        • Ketan__Patel__0011
          Ketan__Patel__0011 @SGaist last edited by Ketan__Patel__0011

          @SGaist

          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;
          }
          
          
          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Why are you implementing such blocking loops within your MainWindow code ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            Ketan__Patel__0011 1 Reply Last reply Reply Quote 1
            • Ketan__Patel__0011
              Ketan__Patel__0011 @SGaist last edited by Ketan__Patel__0011

              @SGaist

              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;
                      }
              }
              
              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @Ketan__Patel__0011 last edited by

                @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 1 Reply Last reply Reply Quote 2
                • Ketan__Patel__0011
                  Ketan__Patel__0011 @jsulm last edited by

                  @jsulm
                  Thanks For Reply

                  I Understand
                  but now is there any other way to help for this problem ?

                  jsulm 1 Reply Last reply Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @Ketan__Patel__0011 last edited by

                    @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 1 Reply Last reply Reply Quote 0
                    • Ketan__Patel__0011
                      Ketan__Patel__0011 @jsulm last edited by

                      @jsulm

                      Your Suggestion Is Not Wrong

                      jsulm 2 Replies Last reply Reply Quote 0
                      • jsulm
                        jsulm Lifetime Qt Champion @Ketan__Patel__0011 last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • jsulm
                          jsulm Lifetime Qt Champion @Ketan__Patel__0011 last edited by

                          @Ketan__Patel__0011 OK. Then take a look at the alternative I proposed.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post