相关文章推荐
有腹肌的卡布奇诺  ·  C# ...·  8 月前    · 
俊逸的长颈鹿  ·  javascript - ...·  10 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a method which is called from both QThreads and the main thread. this method can sometimes take a long time to do its computations in a loop so I put QCoreApplication::processEvents() and this prevents the GUI from freezing. At some point I had changed QCoreApplication::processEvents() for QApplication::processEvents() but that caused the GUI to freeze (im pretty sure thats what was fereezing it because since I put QCoreApplication::processEvents() back it hasnt frozen again) Am I right to think that calling QApplication::processEvents() from both the main thread and QThreads can freeze the GUI?

Neither, processEvent() should be calld only when you have actual pending events to process. You may find this useful : How to make Qt work when main thread is busy?

I am going to try QtConcurrent::run. Can I do GUI operations in there or should I still emit signals like for the case of a QThread yan bellavance Jan 28, 2010 at 1:05 @yan bellavance: You should emit signals, as it will be in a separate thread. Or you could use the QFuture stuff to help, which will do a lot of creating and emitting the signals for you. Caleb Huitt - cjhuitt Jan 28, 2010 at 19:27

You'll be much better off moving the long-running process out of the main thread so you don't need to call processEvents() . Within that long-running process, you can emit whatever signals you need so the gui has sufficient information to do updates, etc. processEvents , however, is usually a crutch for a poor design.

I am going to try QtConcurrent::run. Can I do GUI operations in there or should I still emit signals like for the case of a QThread yan bellavance Jan 28, 2010 at 1:30 Gui operations may only be performed in the main thread. QtConcurrent is a good idea, especially if you can divide your work up to utilize multiple cores. Kaleb Pederson Jan 28, 2010 at 17:08

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .