zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Qt之根据扩展名获取文件图标、类型

Qt文件 获取 类型 根据 图标 扩展名
2023-09-11 14:19:13 时间

C++根据扩展名获取文件图标、类型一节中我们分享了如何根据扩展名来获取对应的文件图标、类型,下面。我们在Qt中使用它。


std::string strArray[13] = {"folder", ".exe", ".zip", ".har", ".hwl", ".accdb",

 ".xlsx", ".pptx", ".docx", ".txt", ".h", ".cpp", ".pro"};

int nCount = sizeof(strArray) / sizeof(std::string);

for (int i = 0; i nCount ; ++i)

 // 获取图标、类型

 QPixmap pixmap;

 std::string type;

 int nPos = -1;

 nPos = strArray[i].find(".");

 if (nPos = 0)

 // Qt4:QPixmap::fromWinHICON(icon)

 pixmap = QtWin::fromHICON(fileIcon(strArray[i]));

 type = fileType(strArray[i]);

 else

 pixmap = QtWin::fromHICON(folderIcon());

 type = folderType();

 QIcon icon;

 icon.addPixmap(pixmap);

 QString strType = QString::fromLocal8Bit(type.c_str());

 // 添加单元项

 QListWidgetItem *pItem = new QListWidgetItem(pListWidget);

 pItem- setIcon(icon);

 pItem- setText(strType);

 pListWidget- addItem(pItem);

}

在Qt4中,可以通过QPixmap::fromWinHICON(HICON)来转换,但是,到了Qt5以后此接口已经被遗弃了,所以这里使用QtWin::fromHICON(HICON)。


Hi3516开发笔记(十):Qt从VPSS中获取通道图像数据存储为jpg文件 上一篇已经将himpp套入qt的基础上进行开发。那么qt中拿到frame则是很关键的交互,这是qt与海思可能编解码交叉开发的关键步骤。