2014-02-21 65 views
0

我在QTCreator中使用OpenGl。難以鏈接UI樹部件和頭文件/ CPP文件

我很難鏈接我的樹部件(在UI中)和相關的頭文件/ cpp文件。我很確定我的頭文件聲明是正確的。我需要做什麼來執行鏈接?

樹部件已添加到在.pro文件的源列表此文件後已晉升爲myTree

#ifndef MYTREE_H 
#define MYTREE_H 

#include <QTreeWidget> 

class myTree: public QTreeWidget { 

    Q_OBJECT 

public: 
    myTree(QWidget*); 
    myTree(); 
    ~myTree(); 

public slots: 
    void receiveroot(QTreeWidgetItem*); 

}; 

#endif 
+2

你會得到什麼錯誤? – Matthew

+0

'Q_DECLARE_METATYPE(QTreeWidgetItem *)''qRegisterMetaType ();' –

回答

0

,你必須重新運行該項目QMAKE,然後生成它。你的問題很可能是由於moc沒有在這個文件上運行。你的默認構造函數是不必要的,應該給家長一個默認nullptr參數:

public: 
    myTree(QWidget* parent = nullptr); 

我相信你receiveRoot方法看起來有點像下面?

Q_SLOT void receiveRoot(QTreeWidgetItem * item) { 
    QModelIndex index = indexFromItem(item); 
    setRootIndex(index); 
}