Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GUI is Freeze When Start QtConcurrent::run Process

GUI is Freeze When Start QtConcurrent::run Process

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 966 Views
  • 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__0011K Offline
    Ketan__Patel__0011K Offline
    Ketan__Patel__0011
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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__0011K 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        Ketan__Patel__0011K Offline
        Ketan__Patel__0011K Offline
        Ketan__Patel__0011
        wrote on last edited by Ketan__Patel__0011
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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__0011K 1 Reply Last reply
          1
          • SGaistS SGaist

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

            Ketan__Patel__0011K Offline
            Ketan__Patel__0011K Offline
            Ketan__Patel__0011
            wrote on last edited by Ketan__Patel__0011
            #5

            @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;
                    }
            }
            
            jsulmJ 1 Reply Last reply
            0
            • Ketan__Patel__0011K 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;
                      }
              }
              
              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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__0011K 1 Reply Last reply
              2
              • jsulmJ jsulm

                @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__0011K Offline
                Ketan__Patel__0011K Offline
                Ketan__Patel__0011
                wrote on last edited by
                #7

                @jsulm
                Thanks For Reply

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

                jsulmJ 1 Reply Last reply
                0
                • Ketan__Patel__0011K Ketan__Patel__0011

                  @jsulm
                  Thanks For Reply

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

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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__0011K 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @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__0011K Offline
                    Ketan__Patel__0011K Offline
                    Ketan__Patel__0011
                    wrote on last edited by
                    #9

                    @jsulm

                    Your Suggestion Is Not Wrong

                    jsulmJ 2 Replies Last reply
                    0
                    • Ketan__Patel__0011K Ketan__Patel__0011

                      @jsulm

                      Your Suggestion Is Not Wrong

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • Ketan__Patel__0011K Ketan__Patel__0011

                        @jsulm

                        Your Suggestion Is Not Wrong

                        jsulmJ Online
                        jsulmJ Online
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

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

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved