Important: Please read the Qt Code of Conduct -

GUI Freezes while processing files

  • 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!

  • 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.

  • @elveatles what is the difference between the two?

  • @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.

  • 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.
    QThread::currentThreadId() in your implementation, by this you can identify parsing is running in worker thread or main thread.

  • @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();


    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

  • Moderators


    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.

Log in to reply