我用下面笨方法已經可取得full path,請問一下是否有函式可直接取得,我試半天都找不到,有人會嗎?我覺得應該有更好的方法?(努力學Qt的新手)
- 代碼: 選擇全部
void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem* item, int column)
{
//QString str1 = item->text(1); //取得第2欄text
//QString str0 = item->text(0); //取得第1欄text
//QString str0 = ui->treeWidget->selectedItems().value(0)->text(0);//取得第1欄text
//QString str0 = ui->treeWidget->currentItem()->text(0);//取得第1欄text
//QString key = ui->treeWidget->currentItem()->parent()->text(0);//取得上層第1欄text
QString key; //QTreeWidgetItem item text
QString full_path; //檔案路徑
key = item->text(0);
full_path=key+"/";
while (key != "qt")
{
item=item->parent(); //取得上1層item
key = item->text(0); //取得上1層第1欄text
full_path=key+"/"+full_path;
cout <<" 檔案路徑" << full_path.toStdString() << "\n";
}
//QDir dir;
//QString str2 = dir.filePath(key);
ui->listWidget->addItem(full_path); //把字串加到listWidget
}