PDA

View Full Version : Custom QTreeWidgetItem class and signals&slots issue



devla
6th July 2012, 01:10
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.


Class declarations lacks Q_OBJECT macro.

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



#ifndef ETREEWIDGETITEM_H
#define ETREEWIDGETITEM_H

#include <QTreeWidgetItem>
#include "en.h"

class ETreeWidgetItem : public QTreeWidgetItem
{

public:
explicit ETreeWidgetItem(En &en, QTreeWidget *parent=0);

explicit ETreeWidgetItem(En &en, QTreeWidgetItem *parent, int type = Type);

void updateText(void);

void clearChildren(void);

En en;



signals:
void enHasChangedSignal();

public slots:

void enHasChanged();

};

#endif



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

high_flyer
6th July 2012, 12:10
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?

wysota
6th July 2012, 12:24
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.

devla
7th July 2012, 01:15
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.