-5
我正在Qt中解析XML文件,使用QTreeWidget顯示XML的各個部分。我想維護指向每個部分「標題」的指針。返回指針的這些函數調用之間有什麼區別?
我有這些指針定義:
QTreeWidgetItem* groupExport,
groupDesign,
groupSheet,
groupTitleBlock,
groupComponents,
groupLibParts,
groupLibraries,
groupNets;
我有這些functons:
//////////////////////////////////////////////////////////////////////////////
/// treeAddRoot
///---------------------------------------------------------------------------
QTreeWidgetItem* window_Main::treeAddRoot(QString name) {
QTreeWidgetItem *treeRoot = new QTreeWidgetItem(ui->treeSourceFile);
...
return treeRoot;
}
QTreeWidgetItem* window_Main::treeAddRoot(QString name, QString description) {
QTreeWidgetItem *treeRoot = new QTreeWidgetItem(ui->treeSourceFile);
...
return treeRoot;
}
//////////////////////////////////////////////////////////////////////////////
/// treeAddGroup
///---------------------------------------------------------------------------
QTreeWidgetItem* window_Main::treeAddGroup(QTreeWidgetItem *treeParent, QString name) {
QTreeWidgetItem *treeChildGroup = new QTreeWidgetItem(treeParent);
...
return treeChildGroup;
}
QTreeWidgetItem* window_Main::treeAddGroup(QTreeWidgetItem *treeParent, QString name, QString description) {
QTreeWidgetItem *treeChildGroup = new QTreeWidgetItem(treeParent);
...
return treeChildGroup;
}
//////////////////////////////////////////////////////////////////////////////
/// treeAddChild
///---------------------------------------------------------------------------
void window_Main::treeAddChild(QTreeWidgetItem *treeParent, QString name) {
QTreeWidgetItem *treeChild = new QTreeWidgetItem(treeParent);
...
treeParent->addChild(treeChild);
}
void window_Main::treeAddChild(QTreeWidgetItem *treeParent, QString name, QString description) {
QTreeWidgetItem *treeChild = new QTreeWidgetItem(treeParent);
...
}
在解析這些是 「臨時」 的使用規定:
QString tempTag, tempValue;
對於解析代碼,編譯器似乎認爲這是好的:
if (tempTag.contains("export")) {
...
groupExport = treeAddRoot(tempTag);
}
然而,幾行字後,與此:
error: no match for ‘operator=’ (operand types are ‘QTreeWidgetItem’ and ‘QTreeWidgetItem*’)
groupDesign = treeAddGroup(groupExport, tempTag);
^
有人能幫助我理解上的差異,爲什麼編譯確定一個和失敗:
if (tempTag.contains("design")) {
...
groupDesign = treeAddGroup(groupExport, tempTag);
}
與編譯器錯誤在另一 ?
在此先感謝。
「我這些指針定義」只有'groupExport'是一個指針,其餘都正常的情況下。 – Rakete1111
可能的重複:http://stackoverflow.com/questions/13618282/declaring-multiple-object-pointers-on-one-line-causes-compiler-error – Rakete1111