Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 6.2 pixmap(Qt::ReturnByValueConstant) syntax
Forum Updated to NodeBB v4.3 + New Features

Qt 6.2 pixmap(Qt::ReturnByValueConstant) syntax

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 852 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rory_1
    wrote on 23 Jan 2022, 15:57 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Jan 2022, 16:13 last edited by
      #2

      @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 ->.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply 23 Jan 2022, 21:38
      2
      • C Christian Ehrlicher
        23 Jan 2022, 16:13

        @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 ->.

        R Offline
        R Offline
        Rory_1
        wrote on 23 Jan 2022, 21:38 last edited by
        #3

        @Christian-Ehrlicher Hits side of head. Of course. Thank you very much.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 24 Jan 2022, 01:55 last edited by
          #4

          @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
          

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          R 1 Reply Last reply 24 Jan 2022, 14:40
          2
          • J JKSH
            24 Jan 2022, 01:55

            @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
            
            R Offline
            R Offline
            Rory_1
            wrote on 24 Jan 2022, 14:40 last edited by
            #5

            @JKSH Thanks!

            1 Reply Last reply
            0

            1/5

            23 Jan 2022, 15:57

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved