[問題] qt listview問題

看板C_and_CPP作者 (chec)時間7年前 (2017/01/24 10:39), 7年前編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) win7 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) vs2015 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) qt 5.7 問題(Question): http://imgur.com/a/0enEf 大家好 我目前是想要點選listview裡面的某個file 之後 再按下button去把它轉換成其他格式 (button的轉換已經寫好了) 現在需要的是怎樣把我選取的檔名傳出去 (因為button是需要吃到檔名之後才去決定要轉換那個檔案) 看了一下listview的singal好像只能傳index QFrame *treeFrame = new QFrame(ui.centralWidget); treeFrame->setGeometry(0, 0, 300, 300); QDirModel *treeModel = new QDirModel(this); treeModel->setReadOnly(true); treeModel->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name); QListView *list = new QListView(treeFrame); list->setModel(treeModel); list->setRootIndex(treeModel->index("./Rec")); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.242.6.98 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1485225585.A.DB7.html

01/24 14:06, , 1F
利用QModelIndex::data()去取得資料
01/24 14:06, 1F

01/24 14:56, , 2F
非常感謝 已經找到解法了
01/24 14:56, 2F
下面是我的處理方法 QFrame *treeFrame = new QFrame(ui.centralWidget); treeFrame->setGeometry(100, 100, 200, 400); QDirModel *treeModel = new QDirModel(this); treeModel->setReadOnly(true); treeModel->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name); QListView *filelist = new QListView(treeFrame); filelist->setModel(treeModel); filelist->setRootIndex(treeModel->index("./Rec")); QObject::connect(filelist, SIGNAL(clicked(const QModelIndex)), this, SLOT(iniFileGetName(const QModelIndex))); void ouput::iniFileGetName(const QModelIndex &fileIndex) { qDebug()<< fileIndex.data().toString(); iniFileName = "Rec/" +fileIndex.data().toString(); } ※ 編輯: checkIO (210.242.6.98), 01/24/2017 14:57:49
文章代碼(AID): #1OXhvnst (C_and_CPP)