Qt: Program not responding despite separate thread

浪尽此生 提交于 2019-12-14 02:48:31

问题


I have a program written with C++/Qt converting certain game files. This is the first time I've done something like this, so I'm not particularly experienced yet. I've had issues with the window occasionally showing the "Not responding..." message. After reading up on it, the problem seemed to be that the processing was done in the main thread, blocking the gui. So I tried running a separate thread for the actual work being done, however the problem still occurs.

Here's the section creating the extra thread:

QThread* thread = new QThread;
WKConverter* converter = new WKConverter(settings);
converter->moveToThread(thread);
connect(converter, SIGNAL(log(std::string)), this, SLOT(log(std::string)));
connect(converter, SIGNAL(setInfo(std::string)), this, SLOT(setInfo(std::string)));
connect(converter, SIGNAL(createDialog(std::string)), this, SLOT(createDialog(std::string)));
connect(converter, SIGNAL(createDialog(std::string, std::string)), this, SLOT(createDialog(std::string, std::string)));
connect(converter, SIGNAL(createDialog(std::string, std::string, std::string)), this, SLOT(createDialog(std::string, std::string, std::string)));
connect(converter, SIGNAL(setProgress(int)), this, SLOT(setProgress(int)));
connect(converter, SIGNAL(increaseProgress(int)), this, SLOT(increaseProgress(int)));

connect(thread, SIGNAL(started()), converter, SLOT(run(bool)));
connect(converter, SIGNAL(finished()), thread, SLOT(quit()));
connect(converter, SIGNAL(finished()), converter, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
converter->run();

With signals/slots to push updates for a progress bar and a label indicating what's being worked on to the gui. Generally this works, but as said I still encounter the "Not responding..." issue (Though interestingly, this doesn't seem to happen if I'm debugging with Qt Creator, only when running the compiled exe afterwards)

Have I missed something? Is there something else I need to do? I would appreciate any pointers.

If it helps, here is the github for the project, though I have not pushed the work done on threading there yet: https://github.com/Jineapple/WololoKingdoms

来源:https://stackoverflow.com/questions/52081003/qt-program-not-responding-despite-separate-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!