C++ 如何在扩展QTreeWidgetItem而不是QTreeWidget上调用插槽?
我的类位于TaskGenJob.h,其中TaskGenModel继承自QObject:- TaskGenJob.h 在我的TaskGenJob.cpp文件中,我尝试将QTreeWidgetItem的信号连接到updateValue,如下所示 但我得到以下错误:-C++ 如何在扩展QTreeWidgetItem而不是QTreeWidget上调用插槽?,c++,qt,C++,Qt,我的类位于TaskGenJob.h,其中TaskGenModel继承自QObject:- TaskGenJob.h 在我的TaskGenJob.cpp文件中,我尝试将QTreeWidgetItem的信号连接到updateValue,如下所示 但我得到以下错误:- /opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:204:17: note: no known conversion for argument 1 from 'QTree
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:204:17: note: no known conversion for argument 1 from 'QTreeWidgetItem*' to 'const QObject*'
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:217:17: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
static bool connect(const QObject *sender, const QMetaMethod &signal,
^
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:217:17: note: no known conversion for argument 1 from 'QTreeWidgetItem*' to 'const QObject*'
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:337:13: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
inline bool QObject::connect(const QObject *asender, const char *asignal,
错误是因为QTreeWidgetItem不从QObject继承,并且没有SIGNALitemExpandedQTreeWidgetItem*。
在应用程序的GUI中,我有1个QTreeWideget和数千个QTreeWideGetItem子项。我可以找到这些孩子的指针。要求是我必须仅在扩展QTreeWidgetItem子级时调用插槽updateValue。
如何实现这一点?正如错误所说,QTreeWidgetItem不是Q对象的子类,也没有任何信号。QTreeWidget具有这些功能,因此请尝试连接它,方法与您在代码段中所做的相同 QTreeWidget::itemExpanded信号在其任何项展开时发出,而展开的是它的参数中的哪一项
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:204:17: note: no known conversion for argument 1 from 'QTreeWidgetItem*' to 'const QObject*'
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:217:17: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
static bool connect(const QObject *sender, const QMetaMethod &signal,
^
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:217:17: note: no known conversion for argument 1 from 'QTreeWidgetItem*' to 'const QObject*'
/opt/qt_4.8.6/include/linux60_64/gcc48/QtCore/qobject.h:337:13: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
inline bool QObject::connect(const QObject *asender, const char *asignal,