1

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

Jineapple
  • 29
  • 3
  • 2
    provide a [mcve] – eyllanesc Aug 29 '18 at 15:30
  • I'm sorry, but since this isn't an issue with a specific section of the code, I find it difficult to create a minmal example. I can try later if I can create some kind of mock with the same issue, but I have no idea if that will work. – Jineapple Aug 29 '18 at 15:48
  • 2
    Well, if you can not believe that we can, you think that we will take the time to debug a software, here we do not help to implement projects, here we help solve specific problems, a project is too broad. – eyllanesc Aug 29 '18 at 15:50
  • maybe you send signals too often so main thread is unable to process all of them. try to comment out connects that are related to progress and see if it helps – Bearded Beaver Aug 29 '18 at 16:16
  • 1
    Why do you call `converter->run()` from the current thread after moving `converter` to the new thread? That doesn't look right. – G.M. Aug 29 '18 at 16:55
  • G.M. is right. you need `converter->start()` – Bearded Beaver Aug 29 '18 at 17:03
  • Thank you very much, that was indeed the problem. I thought I was starting the new thread, but actually still had the leftover from the version without threads in there, starting it normally. Do you want to add it as an answer so I can accept it? – Jineapple Aug 29 '18 at 17:23

0 Answers0