PDA

View Full Version : Signal/Slot problem by subclassing from QTreeWidgetItem



Jonas_
30th September 2009, 12:01
Hi there,

I've got a Problem. Sorry for my bad english, that the reason why I want to show you my code. This tells more than my 1000 words...
1st my Class,


using namespace MyNamespace;
class MyTreeWidgetItem : public QTreeWidgetItem
{
Q_OBJECT

public:
SingleScanTreeWidgetItem(QTreeWidget *parent);
~SingleScanTreeWidgetItem();

void makeActions(QMenu* menu);

public slots:
void onAction();
};


Okay, and here is my implementation:


MyTreeWidgetItem::MyTreeWidgetItem(QTreeWidget *parent)
: QTreeWidgetItem(parent)
{
setText(0,"The Text");
}

MyTreeWidgetItem::~MyTreeWidgetItem()
{
}

void MyTreeWidgetItem::makeActions(QMenu* menu)
{
QAction* action = new QAction(QString("Test"),menu);
menu->addAction(action);

QObject::connect(action,SIGNAL(triggered()),this,S LOT(onAction()));
}

void MyTreeWidgetItem::onAction()
{
int test(0);
}


So, thats all. But my compiler gives my an error:


CompileError C2665:
'function' : none of the number1 overloads can convert parameter number2 from type 'type'


So whats my mistake? How can I solve this problem?
Did anybody knows that?

Ciao + Thanks

wysota
30th September 2009, 12:39
QTreeWidgetItem does not inherit QObject.

Jonas_
30th September 2009, 12:42
How can I solve this problem?
I want to have a context menu on my TreeWidgetItems.

wysota
30th September 2009, 12:57
You want to have context menu on your table widget, not its items. So implement it there using the regular means available for widgets.

faldzip
30th September 2009, 12:59
first of all your constructor name does not match class name :]
second of all add you context menu to your QTreeWidget not to your items. Then check which item was clicked