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



  • 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)



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



  • @koahnig

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



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



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


Log in to reply