I have inherited a class MainTree
from QTreeview
maintree.cpp file
void MainTree::LaunchTree()
{
//Tree launching
connect(this, SIGNAL(customContextMenuRequested(const QPoint& )),this,SLOT(showCustomContextMenu(const QPoint&)));
}
void MainTree::showCustomContextMenu(const QPoint &pos)
{
//Add actions
}
But i get the following error
QObject::connect: No such slot QTreeView::showCustomContextMenu(const QPoint&)
I could not understand why, am i missing something ??
Definition of the class MainTree
class MainTree : public QTreeView
{
public:
MainTree();
MainTree(QWidget *parent = 0);
public slots:
private slots:
void showCustomContextMenu(const QPoint& pos);
private:
void launchTree();
};
You are missing the
Q_OBJECT
macro out, so try this:Do not forget to re-run qmake after this to regenerate the moc files properly. Make sure you have the moc include at the end of your source code, or you handle the moc generation without that.
Also, note that if you used Qt 5.2 or later with C++11 support, you would get a static assertion about the missing Q_OBJECT macro, so you would not get runtime issues anymore. I suggest to follow that if you can.
When referring to slot and signals you have to omnit all decoration:
const
&
and so on (only star can remain).Also you forgot about
Q_OBJECT
macro.