PDA

View Full Version : Compilation problem, don't know why



yellowmat
1st March 2006, 15:44
Hi,

I am developping a serial port data frame decoder class which inherits from QThread. I have some custom slots and signals so I add the Q_OBJECT macro in my class declaration.

I add a moc step for my class and run the compiler ... I have the followings errors and don't know why neither what to fix.

SerialDataFrameDecoder.cpp
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
moc_SerialDataFrameDecoder.cpp
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(54) : error C2039: 'staticMetaObject' : is not a member of 'QThread'
c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(84) : error C2039: 'qt_cast' : is not a member of 'QThread'
c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(90) : error C2065: 'activate_signal' : undeclared identifier
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(105) : error C2039: 'qt_invoke' : is not a member of 'QThread'
c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(116) : error C2039: 'qt_emit' : is not a member of 'QThread'
c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(123) : error C2511: 'qt_property' : overloaded member function 'bool (int,int,class QVariant *)' not found in 'CSerialDataFrameDecoder'
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(10) : see declaration of 'CSerialDataFrameDecoder'
c:\qt\serialdataframedecoder\widgetsource\moc_seri aldataframedecoder.cpp(127) : error C2511: 'qt_static_property' : overloaded member function 'bool (class QObject *,int,int,class QVariant *)' not found in 'CSerialDataFra
meDecoder'
c:\qt\serialdataframedecoder\widgetsource\serialda taframedecoder.h(10) : see declaration of 'CSerialDataFrameDecoder'
Error executing cl.exe.

My class declaration is the folowing

#ifndef _SERIAL_DATA_FRAME_DECODER_H
#define _SERIAL_DATA_FRAME_DECODER_H



#include <qthread.h>



class CSerialDataFrameDecoder : public QThread
{
Q_OBJECT

// Constructor / Destructor
public:
CSerialDataFrameDecoder();

// Slots
public slots:
void startDecode();
void stopDecode();

// Signals
signals:
void serialDataFrameDecoded();

// Functions
virtual void run();
};

#endif

and my class implementation is the following

#include "SerialDataFrameDecoder.h"



// Constructor / Destructor
CSerialDataFrameDecoder::CSerialDataFrameDecoder()
{
}

// Slots
void CSerialDataFrameDecoder::startDecode()
{
}


void CSerialDataFrameDecoder::stopDecode()
{
}


// Functions
void CSerialDataFrameDecoder::run()
{
}

So what's wrong ?

Thanks in advance

jacek
1st March 2006, 15:49
QThread doesn't inherit QObject, so you can't use signals and slot with it.

Remember that in Qt3 you can't send signals across different threads --- you must use custom events for this.

yellowmat
1st March 2006, 16:08
It is not possible to use slots and signals in my class ?

Ok, then I will use custom events instead.

Thank you very much jacek for your high speed and accuracy answer :)

jacek
1st March 2006, 16:31
It is not possible to use slots and signals in my class ?
You could use multiple inheritance, but it won't work with QThread.

yellowmat
2nd March 2006, 16:22
I did not use multiple inheritance but custom events instead. It's quite simple and works well.

Why is it not possible to use slots and signals over distinct threads as you told me ?

Thanks.

jacek
2nd March 2006, 16:31
Why is it not possible to use slots and signals over distinct threads as you told me ?


From Qt docs (http://doc.trolltech.com/3.3/threads.html#8):
The Signals and Slots mechanism can be used in separate threads, as long as the rules for QObject based classes are followed. The Signals and Slots mechanism is synchronous: when a signal is emitted, all slots are called immediately. The slots are executed in the thread context that emitted the signal.
Warning: Slots that generate window system events or use window system functions must not be connected to a signal that is emitted from a thread that is not the GUI thread. See the Qt Library Mutex section above for more details.
This says you can use them under certain conditions, but this:

None of the QObject based classes included in the Qt library are reentrant. [...] QObject and all of its subclasses are not thread-safe.
says that you probably won't be able to meet those conditions.

If you want to use signals & slots across threads, switch to Qt4 and use queued connections.

yellowmat
2nd March 2006, 16:36
This is a great pleasure to chat with the Qt master you are :o

I hope that one day I will be able to help newbies like you do.