View Full Version : Signal puzzle

16th October 2018, 20:54
This puzzle probably has a simple answer.

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

class QVideoOutput : public QObject
QVideoOutput(QObject * parent=0, int source=0, vtkRenderWindow *VTKrenWin=0);
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.

16th October 2018, 22:38
You forgot the Q_OBJECT macro in the class definition - http://doc.qt.io/qt-5/qobject.html#Q_OBJECT

17th October 2018, 00:07
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

17th October 2018, 08:12
Hi, did you add the generated moc_qvideooutput.cpp file to your project?


17th October 2018, 15:38
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.


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.