Qt 6.2 pixmap(Qt::ReturnByValueConstant) syntax
-
wrote on 23 Jan 2022, 15:57 last edited by
I need some syntax help. I'm updating deprecated code in Qt 5.15 for QLabel::pixmap(). I have a QLabel *progress. My current code:
int w = progress->pixmap()->width(); // works in Qt 5.15
I am trying to change to the new QPixmap::pixmap(Qt::ReturnByValueConstant) const
I have tried:int w = progress->pixmap(Qt::ReturnByValueConstant)->width(); // does not work
I am getting an error: expected '(' for function-style cast or type construction. The Qt namespace documentation says Qt::ReturnByValueConstant is a dummy enum.
So I tried:
int w = progress->pixmap(Qt::ReturnByValueConstant())->width(); // appears to work
Is this the correct syntax?
-
@Rory_1 said in Qt 6.2 pixmap(Qt::ReturnByValueConstant) syntax:
Qt::ReturnByValueConstant
pixmap(Qt::ReturnByValueConstant) returns (as the enum properly says) an object, not a pointer to an object. So you should use
.
instead->
. -
@Rory_1 said in Qt 6.2 pixmap(Qt::ReturnByValueConstant) syntax:
Qt::ReturnByValueConstant
pixmap(Qt::ReturnByValueConstant) returns (as the enum properly says) an object, not a pointer to an object. So you should use
.
instead->
.wrote on 23 Jan 2022, 21:38 last edited by@Christian-Ehrlicher Hits side of head. Of course. Thank you very much.
-
@Rory_1 And after you've updated all your deprecated code, disable all deprecated functions (for example, by setting
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x051500
in your .pro file). Once you've done this, you can clean up your code by getting rid of the dummy enum:// int w = progress->pixmap()->width(); // Original code, deprecated // int w = progress->pixmap(Qt::ReturnByValueConstant).width(); // Transition code int w = progress->pixmap().width(); // Final code
-
@Rory_1 And after you've updated all your deprecated code, disable all deprecated functions (for example, by setting
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x051500
in your .pro file). Once you've done this, you can clean up your code by getting rid of the dummy enum:// int w = progress->pixmap()->width(); // Original code, deprecated // int w = progress->pixmap(Qt::ReturnByValueConstant).width(); // Transition code int w = progress->pixmap().width(); // Final code
1/5