fpdragon
fpdragon

Reputation: 1937

Custom QSpinBox -> not compileable

The plan is to get a possibility to customize a QSpinBox for hex view for example. I found some examples on the Internet and tried my self with my own version. Every time I get similar linker errors. Since I'm no QT expert I hope someone here could help:

The Error:

1>CustomSpinBox.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CustomSpinBox::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CustomSpinBox@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>CustomSpinBox.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CustomSpinBox::qt_metacast(char const *)" (?qt_metacast@CustomSpinBox@@UAEPAXPBD@Z)
1>CustomSpinBox.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CustomSpinBox::metaObject(void)const " (?metaObject@CustomSpinBox@@UBEPBUQMetaObject@@XZ)

Here is a sample code I found.

https://bitbucket.org/megazig/megagecko/src/c20ec5e7003c/src/qhexspinbox.h

https://bitbucket.org/megazig/megagecko/src/c20ec5e7003c/src/qhexspinbox.cpp

My version is just a little bit easier. I have just this CustomSpinBox class which I wanted to integrate by the promotion feature of QT Designer. The problem is I even can't compile this class... Please help...

I'm using QT 4.7.4 with Visual C++ 2010 and these errors are coming from Visual Studio.

Upvotes: 0

Views: 254

Answers (2)

j_kubik
j_kubik

Reputation: 6181

You need to moc your class definition, but it should to be done automatically. Are you using qmake to compile your project? Is definition of your class in *.h file? Is this *.h file added to HEADERS list in your project file?

Alternatively, if you do't use properties, metaobjects, or add any new signals/slots to your class, you can simply ommit Q_OBJECT from your class definition.

Upvotes: 1

Dave Mateer
Dave Mateer

Reputation: 17946

Make sure you include the Q_OBJECT macro in your CustomSpinBox.h file, and then run qmake on your project to get the moc-ed content generated.

Upvotes: 1

Related Questions