Solved QThread freezes whole app.
-
@Engelard
Hi you have included QObject in worker class ?
class Worker : public QObject {
Q_OBJECT <<<<< -
@mrjj ah, forgot about that macro(never notice that, it always awtomaticly was created by QT)
Now i add it, and it adds me even more errors, but here is whole my code of worker header file:
#pragma once #include <QtCore> #include <QObject> #include <Windows.h> class TestThreads : public QObject { Q_OBJECT public: TestThreads(); static unsigned int addressNow; unsigned int addressMAX = 10; int myValue; bool scanDone = false; DWORD objID; public slots: void scanProcess(); signals: void addressFound(unsigned int addr); void addressValue(int val); void scanFinished(); };
And the result of adding that Q_OBJECT macro is this:
-
@Engelard
Well that is a normal case
Clean your build folder ( just delete all files)
and then run qmake.
Then rebuild all and it should be happy. -
@mrjj now there is new 3 errors)
-
@Engelard
Hi
Its "already defined" so check your .pro file
if you have the file(s) included twice for some reason. -
@mrjj nope, everything fine in there, all i have there is mentioned only once
-
@Engelard
hmm.
what files does class TestThread live it ?
Also did you give your signals a body in cpp for
void addressFound(unsigned int addr);
void addressValue(int val);
void scanFinished();
as it seems to complain about those.
(signals should not have a body) -
(signals should not have a body)
OMG, i didnt know, and as habbit i ofcource gave body(definitions) for every signal function.
Now its working, and threads working perfectly, thank you!
-
@Engelard
Yep its a true classic as normally u must always give a body or it complains about that.
but signals are just the signatures. -
@Engelard you need to properly tag people😉
Anyway QtConcurrent is its own modul, you‘ll need to add it in your pro file as such, as it is stated in the docuQT += concurrent
than it should work, now that you have removed the function body of the signal ☺️