qt - How to work with QGraphicsScene::addPixmap when it only accepts const QPixmap? -


I would like to display QGraphicsScene through some QImage My code is very straightforward:

mainwindow.h

  QImage * sourceImage; QGraphicsView * imageView; QGraphicsScene * imageScene;   

mainwindow.cpp

  imageScene = new QGraphicsScene; ImageView = New QGraphicsView; ImageView-> SetScene (imageScene); SourceImage = new QImage; SourceImage.load (": / targetimage.png"); ImageScene.addPixmap (QPixmap :: fromImage (sourceImage));   

And after that the complainant has stated that whatever I did wrong: only accept const QPixmap as argument, and I QImage < / Code> const QPixmap is not allowed, because accept const QImage within QPixmap :: fromImage , such as Const hell

This method does not make much sense to me, if I want to create an image viewer, for example, and during the runtime, I definitely have to load different images QImage sourceImage < / Code>, and how can I do that a const QImage ?

Using this problem has become sick, thanks for any advice, can you give me a little bit light if there is any vision on philosophical reasons, how do people in QT make these methods Are const ?

Try

  imageScene.addPixmap (QPixmap :: fromImage ( * Source image));   

Some advice:

There is no need to allocate the keys to the pile (new experiment). Use:

  QImage source image;   

Then you do not need to call QPixmap :: fromImage

when you call, just to clarify : Constness has nothing to do with error.

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -