PDA

View Full Version : simple question:the slot and signal of QTreeWidget



weixj2003ld
20th April 2009, 17:08
I create a class as follows:


class CTreeClass:public QTreeWidget
{
public:
CTreeClass(QWidget *parent);
public slots:
void showMessage(QTreeWidgetItem *item, int index);
};

and in the function CTreeClass,the part of code as follows:


CTreeClass::CTreeClass(QWidget *parent)
:QTreeWidget(parent)
{
...
QObject::connect(this,SIGNAL(itemClicked(QTreeWidg etItem *, int)),this,SLOT(showMessage(QTreeWidgetItem *, int)));
....
}

The function showMessage is only show a message(as a test),but when I click the item of the tree,nothing does,Why?

caduel
20th April 2009, 17:37
you forgot the Q_OBJECT macro in your class (whenever you declare a signal or slot, you need this macro in the class)

weixj2003ld
21st April 2009, 03:00
Thanks a lot.
But if I add the Q_OBJECT to my program,and compile it,the errors occur:


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

aamer4yu
21st April 2009, 06:27
Try rebuilding the project ...
from step to making project file...(qmake -tp vc :::in windows)