我在TaskGenJob.h中有我的课程,其中TaskGenModel继承自QObject:-

TaskGenJob.h

class TaskGenJob : public TaskGenModel
{
    Q_OBJECT
public:
    TaskGenJob();
    ~TaskGenJob();
}

TaskGenJob::TaskGenJob()
{
//Connect signal itemExpanded to updateValue so that Display is updated only on tree expansion

connect(TaskGenJobDisplayPtr->getTaskGenJobTreeWdiget(), SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(updateValue()));
}


在我的TaskGenJob.cpp文件中,我尝试将QTreeWidgetItem的Signal连接到上述的updateValue。

但是我收到以下错误:

/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并且不具有SIGNAL(itemExpanded(QTreeWidgetItem*))
在我的应用程序的GUI中,我有1个QTreeWideget和数千个QTreeWidgetItem子级。我可以访问这些孩子的指针。要求是我只能在扩展SLOT updateValue子代时调用QTreeWidgetItem
我该如何实现?

最佳答案

如错误所述,QTreeWidgetItem不是Q对象的子类,也没有任何信号。 QTreeWidget具有这些功能,因此请尝试以与您在代码段中相同的方式连接起来。

QTreeWidget :: itemExpanded信号在其任何一项被展开并且其参数中被展开时发出。

关于c++ - 如何在扩展QTreeWidgetItem而不是QTreeWidget上调用SLOT?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46824310/

10-12 03:21