Results 1 to 4 of 4

Thread: simple question:the slot and signal of QTreeWidget

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default simple question:the slot and signal of QTreeWidget

    I create a class as follows:
    Qt Code:
    1. class CTreeClass:public QTreeWidget
    2. {
    3. public:
    4. CTreeClass(QWidget *parent);
    5. public slots:
    6. void showMessage(QTreeWidgetItem *item, int index);
    7. };
    To copy to clipboard, switch view to plain text mode 
    and in the function CTreeClass,the part of code as follows:
    Qt Code:
    1. CTreeClass::CTreeClass(QWidget *parent)
    2. :QTreeWidget(parent)
    3. {
    4. ...
    5. QObject::connect(this,SIGNAL(itemClicked(QTreeWidgetItem *, int)),this,SLOT(showMessage(QTreeWidgetItem *, int)));
    6. ....
    7. }
    To copy to clipboard, switch view to plain text mode 
    The function showMessage is only show a message(as a test),but when I click the item of the tree,nothing does,Why?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple question:the slot and signal of QTreeWidget

    you forgot the Q_OBJECT macro in your class (whenever you declare a signal or slot, you need this macro in the class)

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple question:the slot and signal of QTreeWidget

    Thanks a lot.
    But if I add the Q_OBJECT to my program,and compile it,the errors occur:
    Qt Code:
    1. cprojecttree.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CTreeClass::metaObject(void)const " (?metaObject@CTreeClass@@UBEPBUQMetaObject@@XZ)
    2. cprojecttree.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CTreeClass::qt_metacast(char const *)" (?qt_metacast@CTreeClass@@UAEPAXPBD@Z)
    3. 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)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple question:the slot and signal of QTreeWidget

    Try rebuilding the project ...
    from step to making project file...(qmake -tp vc :::in windows)

Similar Threads

  1. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  2. retrieving signal name in a slot
    By Baschterl in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 20:44
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.