Results 1 to 5 of 5

Thread: Signal puzzle

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Signal puzzle

    This puzzle probably has a simple answer.

    I have a class QVideoOutput. In qvideooutput.h I have:

    class QVideoOutput : public QObject
    {
    public:
    QVideoOutput(QObject * parent=0, int source=0, vtkRenderWindow *VTKrenWin=0);
    ...
    signals:
    void CB_signal();

    and in MainWindow.cpp:

    videoVTK = new QVideoOutput(this, VTK_SOURCE, renWin);
    connect(videoVTK,SIGNAL(CB_signal()),this,SLOT(set _CheckBox_recording_off()));

    So far so good - this builds successfully. But when I add code to emit the signal in a function in qvideooutput.cpp:

    emit CB_signal();

    I get a link error:

    qvideooutput.obj : error LNK2019: unresolved external symbol "protected: void __thiscall QVideoOutput::CB_signal(void)" (?CB_signal@QVideoOutput@@IAEXXZ) referenced in function "public: void __thiscall QVideoOutput::stopRecorder(void)" (?stopRecorder@QVideoOutput@@QAEXXZ)
    release\dna_gui.exe : fatal error LNK1120: 1 unresolved externals

    I have done similar things in other programs, which worked, but obviously there's something different about this situation.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal puzzle

    You forgot the Q_OBJECT macro in the class definition - http://doc.qt.io/qt-5/qobject.html#Q_OBJECT

  3. The following user says thank you to ChristianEhrlicher for this useful post:

    gib (17th October 2018)

  4. #3
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Signal puzzle

    Unfortunately, that generates 3 new link errors (I have commented out the 'emit' statement.)

    qvideooutput.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QVideoOutput::metaObject(void)const " (?metaObject@QVideoOutput@@UBEPBUQMetaObject@@XZ)
    qvideooutput.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QVideoOutput::qt_metacast(char const *)" (?qt_metacast@QVideoOutput@@UAEPAXPBD@Z)
    qvideooutput.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QVideoOutput::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QVideoOutput@@UAEHW4Call@QMetaObject @@HPAPAX@Z)
    release\dna_gui.exe : fatal error LNK1120: 3 unresolved externals

  5. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal puzzle

    Hi, did you add the generated moc_qvideooutput.cpp file to your project?

    Ginsengelf

  6. The following user says thank you to Ginsengelf for this useful post:

    gib (17th October 2018)

  7. #5
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Signal puzzle

    I did not. I thought any moc_* files were added automatically (in QtCreator) - I see other moc_ files in the source and build\release directories, that do not appear in the source list in QtCreator. In any case, moc_qvideooutput.cpp does not appear anywhere, so I guess it was not generated.

    Gib

    Edit:
    I had to 'Run qmake' after Clean and before Build, and now it builds without errors, and emit CB_signal works!
    Thanks to you both.
    Last edited by gib; 17th October 2018 at 16:23.

Similar Threads

  1. Replies: 3
    Last Post: 6th November 2010, 09:59
  2. puzzle about change QModelIndex's position?
    By Raul in forum Qt Programming
    Replies: 3
    Last Post: 27th October 2010, 10:54
  3. puzzle about toolkits and frameworks
    By Raul in forum General Programming
    Replies: 1
    Last Post: 24th July 2010, 10:05
  4. Puzzle Example on Qt's website
    By yakuzan in forum Newbie
    Replies: 1
    Last Post: 27th May 2010, 06:43
  5. An example puzzle me, please help
    By HelloDan in forum Newbie
    Replies: 6
    Last Post: 8th March 2009, 09:47

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.