如何使用QImage的load方法和qrc文件
最近的项目中要用到QImage的load方法为项目加入一个图标, 通过查找资料和自己的试验,需要修改两个地方:
(1) cpp文件
void
TitleBar::LoadImages()
{
if (mMenuButtonImage != NULL)
return ;
QString file = QString::fromUtf8( " :/Images/MenuButton.bmp " );
mMenuButtonImage = new QImage();
mMenuButtonImage -> load(file, " BMP " );
}
{
if (mMenuButtonImage != NULL)
return ;
QString file = QString::fromUtf8( " :/Images/MenuButton.bmp " );
mMenuButtonImage = new QImage();
mMenuButtonImage -> load(file, " BMP " );
}
(2) Image.qrc文件
<!
DOCTYPE RCC
>
<
RCC
version
="1.0"
>
< qresource >
< file > Images/ExtractEdges.ico </ file >
< file > Images/OpenFile.ico </ file >
< file > Images/MenuButton.bmp </ file >
</ qresource >
</ RCC >
< qresource >
< file > Images/ExtractEdges.ico </ file >
< file > Images/OpenFile.ico </ file >
< file > Images/MenuButton.bmp </ file >
</ qresource >
</ RCC >
也就是,用QString::fromUtf8得到文件的路径,然后修改qrc文件,将Image的信息加到qrc文件中,这样就可以使用了.