连接:没有这样的插槽QTreeView [英] Connect: No such Slot QTreeView
问题描述
我继承了 MainTree
从 QTreeview
maintree.cpp文件
void MainTree::LaunchTree()
{
//Tree launching
connect(this, SIGNAL(customContextMenuRequested(const QPoint& )),this,SLOT(showCustomContextMenu(const QPoint&)));
}
void MainTree::showCustomContextMenu(const QPoint &pos)
{
//Add actions
}
但我得到以下错误
QObject::connect: No such slot QTreeView::showCustomContextMenu(const QPoint&)
我不明白为什么,我失去了一些东西
I could not understand why, am i missing something ??
类 MainTree的定义
class MainTree : public QTreeView
{
public:
MainTree();
MainTree(QWidget *parent = 0);
public slots:
private slots:
void showCustomContextMenu(const QPoint& pos);
private:
void launchTree();
};
推荐答案
您缺少 Q_OBJECT
宏出来,所以试试这个:
You are missing the Q_OBJECT
macro out, so try this:
class MainTree : public QTreeView
{
Q_OBJECT
// ^^^^^
public:
MainTree();
MainTree(QWidget *parent = 0);
public slots:
private slots:
void showCustomContextMenu(const QPoint& pos);
private:
void launchTree();
};
不要忘记在此之后重新运行qmake以正确重新生成moc文件。确保你在源代码的末尾有moc包含,或者处理没有这种情况的moc生成。
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.
此外,请注意,如果你使用Qt 5.2或更高版本与C ++ 11支持,你会得到一个关于缺少的Q_OBJECT宏的静态断言,所以你不会再遇到运行时问题了。如果可以,我建议你这样做。
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.
这篇关于连接:没有这样的插槽QTreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!