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 Freezes while processing files

GUI Freezes while processing files

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.8k 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.
  • TannerST Offline
    TannerST Offline
    TannerS
    wrote on last edited by
    #1

    I have a small GUI that selects and parses multiple files of 30000 lines of text, and the GUI freezes where it locks up and says, "not responding". I tried researching multi threading but nothing with that was working so I feel I maybe am not doing it right and would like some help. The parsing is during only single method call. I call a method to parse files, then i need that to finish before doing the next task on the files. so If I do multithreading, I need to do that aweay from the GUI thread, then wait for it to finish before calling the other class method. Any help is appreciate, Thank you!

    1 Reply Last reply
    0
    • E Offline
      E Offline
      elveatles
      wrote on last edited by
      #2

      What exactly wasn't working when you tried multithreading? Using QThread or QThreadPool is the way to go and their documentation has examples of how to use it.

      TannerST 1 Reply Last reply
      0
      • E elveatles

        What exactly wasn't working when you tried multithreading? Using QThread or QThreadPool is the way to go and their documentation has examples of how to use it.

        TannerST Offline
        TannerST Offline
        TannerS
        wrote on last edited by
        #3

        @elveatles what is the difference between the two?

        E 1 Reply Last reply
        0
        • TannerST TannerS

          @elveatles what is the difference between the two?

          E Offline
          E Offline
          elveatles
          wrote on last edited by
          #4

          @TannerS said:

          @elveatles what is the difference between the two?

          QThreadPool uses multiple threads and reuses the threads that are not busy while QThread is just one thread. I also forgot to mention QtConcurrent, which is probably the easiest way to do multi-threading.

          1 Reply Last reply
          0
          • yuvaramY Offline
            yuvaramY Offline
            yuvaram
            wrote on last edited by yuvaram
            #5

            Hi @TannerS

            I suspect that the object created for parsing file in main thread and tried to execute in worker thread. But parsing executes in main thread only.
            Try to share the code.
            Use
            QThread::currentThreadId() in your implementation, by this you can identify parsing is running in worker thread or main thread.

            Yuvaram Aligeti
            Embedded Qt Developer
            : )

            TannerST 1 Reply Last reply
            0
            • yuvaramY yuvaram

              Hi @TannerS

              I suspect that the object created for parsing file in main thread and tried to execute in worker thread. But parsing executes in main thread only.
              Try to share the code.
              Use
              QThread::currentThreadId() in your implementation, by this you can identify parsing is running in worker thread or main thread.

              TannerST Offline
              TannerST Offline
              TannerS
              wrote on last edited by
              #6

              @elveatles

              ok, now what is the main difference between those and QtConcurrent?

              I tried using QThread, I modified my code to have my two classes to extended the class and using the .run() method, but i did it the program ran as normal, but it still froze so I am suspecting the multi-threading did not work when calling the .run();

              @yuvaram

              I am still learning this, so I wil ltry to look into what your saying, I also can psot soem code later when I am not in a hurry but it's kinda alot but to sum it all up

              class A - has method to parse files
              class b - does soemthing else needed to do on another thread

              class a mus parse files before class b does its job'

              both classes are members of the mainwindow class (aka the gui)

              so when I press a button in the gui, i need the class a to parse and class b to do it's job

              I am not sure how to use QThread::currentThreadid() but I'll try to look it up, any other suggestions ,sample code or anything would be helpful

              Thanks in advance

              kshegunovK 1 Reply Last reply
              0
              • TannerST TannerS

                @elveatles

                ok, now what is the main difference between those and QtConcurrent?

                I tried using QThread, I modified my code to have my two classes to extended the class and using the .run() method, but i did it the program ran as normal, but it still froze so I am suspecting the multi-threading did not work when calling the .run();

                @yuvaram

                I am still learning this, so I wil ltry to look into what your saying, I also can psot soem code later when I am not in a hurry but it's kinda alot but to sum it all up

                class A - has method to parse files
                class b - does soemthing else needed to do on another thread

                class a mus parse files before class b does its job'

                both classes are members of the mainwindow class (aka the gui)

                so when I press a button in the gui, i need the class a to parse and class b to do it's job

                I am not sure how to use QThread::currentThreadid() but I'll try to look it up, any other suggestions ,sample code or anything would be helpful

                Thanks in advance

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @TannerS

                This question really comes up often in the forums so I suggest looking up some previous posts as well. Additionally, you can look up the very good resources inside the Qt documentation. This blog and this one as well. They're mainly dealing with the "low-level" threading API, but probably you'd be better off using one of the "high-level" primitives - QThreadPool (and this blog post) and the Qt concurrent module.

                Subclassing QThread and reimplementing QThread::run is possible, but you have to be prepared to syncronize your thread manually (by means of mutexes and/or semaphores), so it's not for the faint of heart.

                Kind regards.

                Read and abide by the Qt Code of Conduct

                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