【发布时间】:2014-03-06 10:33:11
【问题描述】:
我从QTreeview继承了一个类MainTree
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&)
我不明白为什么,我错过了什么吗??
类MainTree的定义
class MainTree : public QTreeView
{
public:
MainTree();
MainTree(QWidget *parent = 0);
public slots:
private slots:
void showCustomContextMenu(const QPoint& pos);
private:
void launchTree();
};
【问题讨论】:
-
你能显示
MainTree的类定义吗? -
您忘记在类声明的开头添加
Q_OBJECT宏。 -
我之前也尝试过这样做。但是当我添加宏 Q_OBJECTm 时,出现以下错误。 Q_OBJECT 抛出“未定义的 vtable 引用”错误
-
@user3387634 在构建项目之前不要忘记再次运行
qmake。 -
此错误通常表示构建缓存已损坏。清理项目并重新构建它。
标签: c++ qt qobject qtcore qt-signals