Results 1 to 7 of 7

Thread: Compilation problem, don't know why

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Compilation problem, don't know why

    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.
    Qt Code:
    1. SerialDataFrameDecoder.cpp
    2. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
    3. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
    4. moc_SerialDataFrameDecoder.cpp
    5. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
    6. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(12) : error C2061: syntax error : identifier 'QVariant'
    7. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(54) : error C2039: 'staticMetaObject' : is not a member of 'QThread'
    8. c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
    9. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(84) : error C2039: 'qt_cast' : is not a member of 'QThread'
    10. c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
    11. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(90) : error C2065: 'activate_signal' : undeclared identifier
    12. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(105) : error C2039: 'qt_invoke' : is not a member of 'QThread'
    13. c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
    14. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(116) : error C2039: 'qt_emit' : is not a member of 'QThread'
    15. c:\qt\3.3.3\include\qthread.h(56) : see declaration of 'QThread'
    16. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(123) : error C2511: 'qt_property' : overloaded member function 'bool (int,int,class QVariant *)' not found in 'CSerialDataFrameDecoder'
    17. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(10) : see declaration of 'CSerialDataFrameDecoder'
    18. c:\qt\serialdataframedecoder\widgetsource\moc_serialdataframedecoder.cpp(127) : error C2511: 'qt_static_property' : overloaded member function 'bool (class QObject *,int,int,class QVariant *)' not found in 'CSerialDataFra
    19. meDecoder'
    20. c:\qt\serialdataframedecoder\widgetsource\serialdataframedecoder.h(10) : see declaration of 'CSerialDataFrameDecoder'
    21. Error executing cl.exe.
    To copy to clipboard, switch view to plain text mode 

    My class declaration is the folowing
    Qt Code:
    1. #ifndef _SERIAL_DATA_FRAME_DECODER_H
    2. #define _SERIAL_DATA_FRAME_DECODER_H
    3.  
    4.  
    5.  
    6. #include <qthread.h>
    7.  
    8.  
    9.  
    10. class CSerialDataFrameDecoder : public QThread
    11. {
    12. Q_OBJECT
    13.  
    14. // Constructor / Destructor
    15. public:
    16. CSerialDataFrameDecoder();
    17.  
    18. // Slots
    19. public slots:
    20. void startDecode();
    21. void stopDecode();
    22.  
    23. // Signals
    24. signals:
    25. void serialDataFrameDecoded();
    26.  
    27. // Functions
    28. virtual void run();
    29. };
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 

    and my class implementation is the following
    Qt Code:
    1. #include "SerialDataFrameDecoder.h"
    2.  
    3.  
    4.  
    5. // Constructor / Destructor
    6. CSerialDataFrameDecoder::CSerialDataFrameDecoder()
    7. {
    8. }
    9.  
    10. // Slots
    11. void CSerialDataFrameDecoder::startDecode()
    12. {
    13. }
    14.  
    15.  
    16. void CSerialDataFrameDecoder::stopDecode()
    17. {
    18. }
    19.  
    20.  
    21. // Functions
    22. void CSerialDataFrameDecoder::run()
    23. {
    24. }
    To copy to clipboard, switch view to plain text mode 

    So what's wrong ?

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compilation problem, don't know why

    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.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Compilation problem, don't know why

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compilation problem, don't know why

    Quote Originally Posted by yellowmat
    It is not possible to use slots and signals in my class ?
    You could use multiple inheritance, but it won't work with QThread.

  5. The following user says thank you to jacek for this useful post:

    yellowmat (2nd March 2006)

  6. #5
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Compilation problem, don't know why

    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compilation problem, don't know why

    Quote Originally Posted by yellowmat
    Why is it not possible to use slots and signals over distinct threads as you told me ?
    From Qt docs:
    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.

  8. The following user says thank you to jacek for this useful post:

    yellowmat (2nd March 2006)

  9. #7
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Compilation problem, don't know why

    This is a great pleasure to chat with the Qt master you are

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

Similar Threads

  1. Compilation problem with QSqlQuery::bindValue()
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2013, 22:30
  2. MacOS and ibase compilation problem
    By giandrea77 in forum Qt Programming
    Replies: 0
    Last Post: 20th January 2009, 13:04
  3. QT 4.4.1 compilation problem on Windows using nmake
    By operis in forum Installation and Deployment
    Replies: 1
    Last Post: 1st September 2008, 10:08
  4. sub-dir compilation problem
    By Salazaar in forum Newbie
    Replies: 13
    Last Post: 2nd November 2007, 21:48
  5. qt4 compilation problem
    By aegis in forum Installation and Deployment
    Replies: 9
    Last Post: 22nd February 2007, 23:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.