qdir對跨平台的目錄操作提供了很多的便利,為了更加友善的提供全局資源的查找,qdir提供了搜尋路徑替換功能,解決了資源搜尋不便的問題,也能提高檔案查找的效率。
qdir通過已知的路徑字首去搜尋并定位檔案,搜尋路徑增加是有序的。從第一個設定的搜尋路徑開始,是不是覺得和cocos2d的路徑搜尋非常相似呢。
見如下qt的原版例子
qdir::setsearchpaths("icons", qstringlist(qdir::homepath() + "/images"));
qdir::setsearchpaths("docs",qstringlist(":/embeddeddocuments"))
...
qpixmap pixmap("icons:undo.png"); //搜尋undo.png在qdir::homepath() + "/images"
qfile file("docs:design.odf"); //搜尋在:/embeddeddocuments