Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Why is Icon (enum) in QMessageBox have so strange form?
Qt 6.11 is out! See what's new in the release blog

Why is Icon (enum) in QMessageBox have so strange form?

Scheduled Pinned Locked Moved Solved C++ Gurus
5 Posts 4 Posters 1.6k 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.
  • G Offline
    G Offline
    GRUB_666
    wrote on last edited by
    #1

    Hi! I have researched qt files, I have paid attention to such form of enum announcement:

    enum Icon {
            // keep this in sync with QMessageDialogOptions::Icon
            NoIcon = 0,
            Information = 1,
            Warning = 2,
            Critical = 3,
            Question = 4
        };
    

    What need in hand initializate of elements of enum?

    (Sorry, if my english is bad)

    K 1 Reply Last reply
    0
    • G GRUB_666

      Hi! I have researched qt files, I have paid attention to such form of enum announcement:

      enum Icon {
              // keep this in sync with QMessageDialogOptions::Icon
              NoIcon = 0,
              Information = 1,
              Warning = 2,
              Critical = 3,
              Question = 4
          };
      

      What need in hand initializate of elements of enum?

      (Sorry, if my english is bad)

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @GRUB_666

      Hi and welcome to devnet forum

      See https://en.cppreference.com/w/cpp/language/enum

      enums allow only certain values. In this specific case only integer values from 0 to 4. To use Information is more descriptive than 1 and so on.
      It is not absolutely required to do this way, but it most descriptive too. Everybody sees immediately what to expect when assigned to int or for simple output. It is merely a matter of taste.

      Vote the answer(s) that helped you to solve your issue(s)

      G Pl45m4P 2 Replies Last reply
      4
      • K koahnig

        @GRUB_666

        Hi and welcome to devnet forum

        See https://en.cppreference.com/w/cpp/language/enum

        enums allow only certain values. In this specific case only integer values from 0 to 4. To use Information is more descriptive than 1 and so on.
        It is not absolutely required to do this way, but it most descriptive too. Everybody sees immediately what to expect when assigned to int or for simple output. It is merely a matter of taste.

        G Offline
        G Offline
        GRUB_666
        wrote on last edited by
        #3

        @koahnig

        Thank you, I actualy thought that this have any serious reasons.

        1 Reply Last reply
        0
        • K koahnig

          @GRUB_666

          Hi and welcome to devnet forum

          See https://en.cppreference.com/w/cpp/language/enum

          enums allow only certain values. In this specific case only integer values from 0 to 4. To use Information is more descriptive than 1 and so on.
          It is not absolutely required to do this way, but it most descriptive too. Everybody sees immediately what to expect when assigned to int or for simple output. It is merely a matter of taste.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @koahnig

          I think the question was WHY is enum is explicitly initialized with 0 to 4, in fact that enums start with 0 ascending, if you dont set any custom value.

          That NoIcon is equal to INT 0, Information to 1 etc... is self explanatory, I assume


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            At a glance verification of an enums value rather than counting lines. Saves coder time. One goal of good programming is being able to maintain code. So making it easier to troubleshoot a value quickly meets that requirement.

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            2

            • Login

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