Results 1 to 3 of 3

Thread: Emit signal from thread

  1. #1
    Join Date
    Oct 2009
    Posts
    29
    Thanks
    4

    Default Emit signal from thread

    hi, im having a strange problem when trying to emit a signal from a thread.

    thread.h:

    Qt Code:
    1. #ifndef USBCOM_H
    2. #define USBCOM_H
    3.  
    4. #include <QObject>
    5. #include <QThread>
    6.  
    7. class UsbCom : public QThread
    8. {
    9. public:
    10. UsbCom();
    11. void run();
    12.  
    13. signals:
    14. void error(QString error);
    15. };
    16.  
    17. #endif // USBCOM_H
    To copy to clipboard, switch view to plain text mode 

    thread.cpp:

    Qt Code:
    1. #include "usbcom.h"
    2. #include <QtGui>
    3.  
    4. UsbCom::UsbCom()
    5. {
    6. }
    7.  
    8. void UsbCom::run()
    9. {
    10. emit error("error!");
    11. }
    To copy to clipboard, switch view to plain text mode 

    now when trying to compile this program i am getting an undefined refference error from the compiler.

    Qt Code:
    1. Running build steps for project Project...
    2. Configuration unchanged, skipping QMake step.
    3. Starting: /usr/bin/make -w
    4. make: Entering directory `/home/sisco/Documents/School/Project 3/Project Software/Project'
    5. g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/home/sisco/qtsdk-2009.04/qt/mkspecs/linux-g++-64 -I. -I/home/sisco/qtsdk-2009.04/qt/include/QtCore -I/home/sisco/qtsdk-2009.04/qt/include/QtGui -I/home/sisco/qtsdk-2009.04/qt/include -I../../src -I../../src -Imoc -I. -o obj/project.o project.cpp
    6. g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/home/sisco/qtsdk-2009.04/qt/mkspecs/linux-g++-64 -I. -I/home/sisco/qtsdk-2009.04/qt/include/QtCore -I/home/sisco/qtsdk-2009.04/qt/include/QtGui -I/home/sisco/qtsdk-2009.04/qt/include -I../../src -I../../src -Imoc -I. -o obj/usbcom.o usbcom.cpp
    7. g++ -m64 -Wl,-rpath,/home/sisco/qtsdk-2009.04/qt/lib -o ../../examples/bin/Project obj/main.o obj/project.o obj/savedialog.o obj/overwritedialog.o obj/tables.o obj/usbcom.o obj/moc_project.o obj/moc_savedialog.o obj/moc_overwritedialog.o obj/moc_tables.o obj/qrc_icons.o -L/home/sisco/qtsdk-2009.04/qt/lib -L../../lib -lqwt -lusb-1.0 -lQtGui -L/home/sisco/qtsdk-2009.04/qt/lib -L/usr/X11R6/lib64 -pthread -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
    8. obj/usbcom.o: In function `UsbCom::run()':
    9. /home/sisco/Documents/School/Project 3/Project Software/Project/usbcom.cpp:10: undefined reference to `UsbCom::error(QString)'
    10. collect2: ld returned 1 exit status
    11. make: Leaving directory `/home/sisco/Documents/School/Project 3/Project Software/Project'
    12. make: *** [../../examples/bin/Project] Error 1
    13. Exited with code 2.
    14. Error while building project Project
    15. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    code used in my main class:

    Qt Code:
    1. usbcom = new UsbCom();
    2. connect(usbcom, SIGNAL(error(QString)), SLOT(usbError(QString)));
    3. usbcom->start();
    To copy to clipboard, switch view to plain text mode 

    what am i doing wrong?

  2. #2
    Join Date
    Nov 2008
    Location
    Częstochowa/Poland
    Posts
    50
    Thanks
    2
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Emit signal from thread

    You are missing the Q_OBJECT macro in Your class
    Me, Grimlock, not "nice dino". ME BASH BRAINS!

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Emit signal from thread

    You forgot the Q_OBJECT macro...

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  3. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 15:26
  4. emit is slow in Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2007, 09:52
  5. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13

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.