Results 1 to 4 of 4

Thread: Custom QTreeWidgetItem class and signals&slots issue

  1. #1
    Join Date
    Jul 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Custom QTreeWidgetItem class and signals&slots issue

    Hi everybody,

    I have been frustrated due to a problem I could not solve. Hope you can help me. I could not find a source which would make be able to overcome it.

    I have created a class which inherits QTreeWidgetItem. I want to implement custom signals and slots. When I do that I am receiving following error.

    Qt Code:
    1. Class declarations lacks Q_OBJECT macro.
    To copy to clipboard, switch view to plain text mode 

    As far as I know the QTreeWidgetItem class inherits QWidget which inherits QObject so Q_OBJECT macro should not be used in my class. Just out of curiosity i added Q_OBJECT macro too see what happens and I had lots of C2440, C2039, C2664, C2665, etc.

    Somehow I am not able to see available signals and slots on my class when I type connect function somewhere else. I also cannot use connect function inside my class since QObject is not related to my class.

    Here is my class


    Qt Code:
    1. #ifndef ETREEWIDGETITEM_H
    2. #define ETREEWIDGETITEM_H
    3.  
    4. #include <QTreeWidgetItem>
    5. #include "en.h"
    6.  
    7. class ETreeWidgetItem : public QTreeWidgetItem
    8. {
    9.  
    10. public:
    11. explicit ETreeWidgetItem(En &en, QTreeWidget *parent=0);
    12.  
    13. explicit ETreeWidgetItem(En &en, QTreeWidgetItem *parent, int type = Type);
    14.  
    15. void updateText(void);
    16.  
    17. void clearChildren(void);
    18.  
    19. En en;
    20.  
    21.  
    22.  
    23. signals:
    24. void enHasChangedSignal();
    25.  
    26. public slots:
    27.  
    28. void enHasChanged();
    29.  
    30. };
    31.  
    32. #endif
    To copy to clipboard, switch view to plain text mode 


    could anyone help me about it? Thanks a lot in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QTreeWidgetItem class and signals&slots issue

    As far as I know the QTreeWidgetItem class inherits QWidget which inherits QObject
    How did you come to that conclusion?

    I had lots of C2440, C2039, C2664, C2665, etc.
    And you expect us to google these errors, and find out what they are?
    And then guess in which line code in your program they are found?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom QTreeWidgetItem class and signals&slots issue

    Quote Originally Posted by devla View Post
    As far as I know the QTreeWidgetItem class inherits QWidget which inherits QObject
    It would be wise to look into the docs to notice that QTreeWidgetItem does not have any superclasses.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Custom QTreeWidgetItem class and signals&slots issue

    hi again,

    @high_flyer: I have given the compile errors to state that when I added Q_OBJECT to my class they appeared because my class did not have relation with QObject. That's what I meant which was the problem.

    however I mistaken by confusing QTreeWidgetItem with QTreeWidget after working about ten hours yesterday. As soon as I saw your replies the problem was obvious , missed it.

    thanks a lot for the posts.

Similar Threads

  1. Replies: 6
    Last Post: 2nd May 2012, 09:13
  2. Signals not going through to custom class.
    By GunBlade in forum Qt Programming
    Replies: 3
    Last Post: 15th August 2010, 12:50
  3. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 11:14
  4. Replies: 12
    Last Post: 23rd June 2008, 08:05
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.