• 9219阅读
  • 9回复

QPixmap加载错误:discards qualifiers [复制链接]

上一主题 下一主题
离线feixiangxtu
 

只看楼主 倒序阅读 楼主  发表于: 2010-12-13
之前用一个图形文件初始化了这个QPixmap变量。
QPixmap m_hPoint = QPixmap(szResourceName);


现在我想换一个图形文件,相当于该图形状态做了一个变化,所有用另一个图形文件加载之
m_hPoint = QPixmap(szResourceOtherName);


这样产生一个error:
passing 'const QPixmap' as 'this' argument of 'QPixmap& QPixmap::operator=(const QPixmap&)' discards qualifiers


请问有人遇到这个问题过吗?
或者 我该采用什么办法来处理图形的状态变化然后再加载。
离线feixiangxtu

只看该作者 1楼 发表于: 2010-12-13
有人遇到这个错误吗?
或者用同一个对象如何切换一副图片?
离线0354030w

只看该作者 2楼 发表于: 2010-12-13
QPixmap::load
离线dbzhang800

只看该作者 3楼 发表于: 2010-12-14
引用第1楼feixiangxtu于2010-12-13 13:10发表的  :
有人遇到这个错误吗?
或者用同一个对象如何切换一副图片?

可以肯定,你这儿贴的代码和你真正用的代码完全不同。所以,你贴的代码也不会出现你说的错误。

别人根据错误应该能猜出你的代码大致是怎么写的,但可能和我差不多,不想在猜测的基础上回答问题
离线feixiangxtu

只看该作者 4楼 发表于: 2010-12-14
代码示例如下:
m_hPoint为一个公共变量。
我在初始化时加载了一幅默认的图形文件,比如png图标。
void LoadImagePoint(QString szResourceName)
{
   ...
   m_hPoint = QPixmap(szResourceName);
   ....
}

然后根据外部状态变化更新这个图标:

void RefreshPointStatus()
{
    ...
   m_hPoint = QPixmap(szNewResourceName);
   ...
}


在此处 m_hPoint = QPixmap(szNewResourceName);产生错误:
passing 'const QPixmap' as 'this' argument of 'QPixmap& QPixmap::operator=(const QPixmap&)' discards qualifiers。

我的目的就是想更新某个点的图标。由于是初学者,先请教各位?

谢谢!


离线roywillow

只看该作者 5楼 发表于: 2010-12-14
bool QPixmap::load ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )

Loads a pixmap from the file with the given fileName. Returns true if the pixmap was successfully loaded; otherwise returns false.
The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.
The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed pixmaps and other resource files in the application's executable.
If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.
Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file; the key used is internal and can not be acquired.
See also loadFromData() and Reading and Writing Image Files.
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线pjincz
只看该作者 6楼 发表于: 2010-12-14
~_~ 帅哥问问题太没有诚意了。。
错误提示的意思是,const QPixmap不能放在赋值操作的左侧。
最大的可能是操作m_hPoint的所在函数是const的。
离线feixiangxtu

只看该作者 7楼 发表于: 2010-12-14
5#朋友:我用load还是出现这个错误!
是不是我的这样QPixmap m_hPoint定义有问题了!

6#朋友:我也是刚接触Qt,我好像讲的很清楚啊:更新某个点的图标显示。

还请各位朋友解答。谢谢!
离线dbzhang800

只看该作者 8楼 发表于: 2010-12-14
引用第7楼feixiangxtu于2010-12-14 11:56发表的  :
5#朋友:我用load还是出现这个错误!
是不是我的这样QPixmap m_hPoint定义有问题了!
6#朋友:我也是刚接触Qt,我好像讲的很清楚啊:更新某个点的图标显示。
.......


我前面提到了,你贴的代码不应该存在问题,这说明你的真实的代码和你贴的代码不一致。

这种情况下别人很难帮上你。

题外:你应该是刚接触C++吧?学Qt,C++的基础是不可少的。
离线feixiangxtu

只看该作者 9楼 发表于: 2010-12-14
谢谢 dbzhang800教会了我解决问题的方法:先把基础的东西了解清楚!
快速回复
限100 字节
 
上一个 下一个