[SOLVED] Qt Visual Studio Add-in, Signal & Slots problems
-
I'm trying to compile the basic Qt signal and slots example given "here":http://qt-project.org/doc/qt-4.8/signalsandslots.html with the Visual Studio 2010 add-in (version 1.1.11), and it's giving me a bunch of link errors:
bq. 1>main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Counter::metaObject(void)const " (?metaObject@Counter@@UEBAPEBUQMetaObject@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Counter::qt_metacast(char const *)" (?qt_metacast@Counter@@UEAAPEAXPEBD@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Counter::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Counter@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
1>main.obj : error LNK2019: unresolved external symbol "protected: void __cdecl Counter::valueChanged(int)" (?valueChanged@Counter@@IEAAXH@Z) referenced in function "public: void __cdecl Counter::setValue(int)" (?setValue@Counter@@QEAAXH@Z)I looked around and it seems to indicate that the project isn't moc'ing correctly, however I'm not sure how to fix this.
This is the code:
@
#include <QtCore/QCoreApplication>class Counter : public QObject
{
Q_OBJECTpublic:
Counter() { m_value = 0; }int value() const { return m_value; }
public slots:
void setValue(int value);signals:
void valueChanged(int newValue);private:
int m_value;
};void Counter::setValue(int value)
{
if (value != m_value) {
m_value = value;
emit valueChanged(value);
}
}int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Counter a1, a2;
QObject::connect(&a1, SIGNAL(valueChanged(int)), &a2, SLOT(setValue(int)));return a.exec();
}@ -
You should add your class declaration in header(.h) file. In VS moc'ing is done only on .h files.
P.S.: you can also add custom Build Step to .cpp files and include .moc in .cpp... -
thanks, that solved my problem.
-
Please add "[SOLVED]" left to the topic subject.