I wanted to create a class in an separate file in Qt and then use this class in my main file (Background: Secondary thread updating GUI). Thus I wrote ReadDPC.h
-file:
class ReadDPC: public QThread
{
//First edit:
Q_OBJECT
//End of first edit
public:
void run();
signals:
void currentCount(int);
};
And in my ReadDPC.cpp
-file:
void ReadDPC::run()
{
while(1)
{
usleep(50);
int counts = read_DPC();
emit currentCount(counts);
}
}
read_DPC()
is a function returning an int
-value also placed in the cpp-file.
But when I want to compile this, I get the error undefined reference to ReadDPC::currentCount(int)
. Why? How can I solve this?
Edit: Added Q_Object
-Macro, no solution.
Add Q_OBJECT macro to your subclass and run qmake.
This macro allows you use signals and slots mechanism. Without this macro moc can't create your signal so you get error that your signal is not exist.
Code should be:
class ReadDPC: public QThread {
Q_OBJECT
Note that when you use new signal and slot syntax, you can get compile time error that you forgot add this macro. If it is interesting for you, read more here: http://qt-project.org/wiki/New_Signal_Slot_Syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With