I want to assign the value of one QPixmap through a function to another QPixmap , but I get an error. Why, and how to do it? Code example:

 class Class { public: void Function(QPixmap pix) { pixmap(pix); } protected: QPixmap pixmap; } 
  • one
    What mistake? How are QPixmap initialized? Lay out a minimal example to reproduce the error. - ߊߚߤߘ
  • Class {public: void Function (QPixmap pix) {pixmap (pix); } protected: QPixmap pixmap; - Astemir Tsechoev

1 answer 1

Correct your code like this:

 void Function(QPixmap pix) { pixmap = pix; } 

I will add more.

Your code is not optimal: you pass an argument to a function by value , i.e. the function receives a copy of the object, the copy constructor is called — a potentially expensive operation, completely redundant in the context of your function.

Pass a constant object reference to the function:

 void Function(const QPixmap& pix) 

or, if you use with ++ 11, use the move semantics (if it is valid in the context of a function call):

 void Function(QPixmap&& pix)