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. From Ubuntu to Windows: Syntax Error C2059 / C2143
Forum Updated to NodeBB v4.3 + New Features

From Ubuntu to Windows: Syntax Error C2059 / C2143

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 8 Posters 1.7k Views 1 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.
  • F fem_dev

    @mrjj Thank you....now its working good!

    Second doubt: I was thinking that 'ERROR' inside the custom enum will not clash with MSVC 2019.
    Why this happen?

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #5

    @fem_dev
    ERROR will be defined in a header file, either an MSVC-specific one or somewhere in some Windows header file. It might be defined in COM.

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

      You have the option of using mingw in windows (basically gcc for windows). This will help avoid these kinds of problems. YMMV.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #7

        @fcarney said in From Ubuntu to Windows: Syntax Error C2059 / C2143:

        This will help avoid these kinds of problems. YMMV.

        No, not in this case. ERROR is a define in a windows header.
        btw: using uppercase in enums is ... strange

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

        J.HilkJ 1 Reply Last reply
        5
        • F fem_dev

          @mrjj Thank you....now its working good!

          Second doubt: I was thinking that 'ERROR' inside the custom enum will not clash with MSVC 2019.
          Why this happen?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @fem_dev You can use "enum class" to avoid name clashes:

          typedef enum class {
              ERROR = -2, // C2059: syntax error: 'constant'
              WARNING = -1,
              STATUS = 0
          } MSG_TYPE;
          

          But then you will need to qualify using enum name:

          MSG_TYPE::ERROR;
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Christian EhrlicherC 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @fcarney said in From Ubuntu to Windows: Syntax Error C2059 / C2143:

            This will help avoid these kinds of problems. YMMV.

            No, not in this case. ERROR is a define in a windows header.
            btw: using uppercase in enums is ... strange

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #9

            @Christian-Ehrlicher said in From Ubuntu to Windows: Syntax Error C2059 / C2143:

            btw: using uppercase in enums is ... strange

            Sadly its mandatory - at least the first letter - if you want to expose your enum to the QML-Engine


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            JonBJ 1 Reply Last reply
            3
            • J.HilkJ J.Hilk

              @Christian-Ehrlicher said in From Ubuntu to Windows: Syntax Error C2059 / C2143:

              btw: using uppercase in enums is ... strange

              Sadly its mandatory - at least the first letter - if you want to expose your enum to the QML-Engine

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #10

              @J-Hilk
              In fairness, the usual way now for an enum is initial capital followed by smalls, which should avoid the calls with ERROR.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #11

                Hi
                Just a note.
                I seen many C(not ++) coding standards that say to use all caps for enum values
                over the years to follow all caps for constants.

                JonBJ 1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  Just a note.
                  I seen many C(not ++) coding standards that say to use all caps for enum values
                  over the years to follow all caps for constants.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #12

                  @mrjj
                  Indeed, that's why I wrote " the usual way now". I think it has changed so that enum constants are like class names. Certainly if you look at https://doc.qt.io/qt-5/qt.html you see all Qt enum values are done that way for their values.

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @fem_dev You can use "enum class" to avoid name clashes:

                    typedef enum class {
                        ERROR = -2, // C2059: syntax error: 'constant'
                        WARNING = -1,
                        STATUS = 0
                    } MSG_TYPE;
                    

                    But then you will need to qualify using enum name:

                    MSG_TYPE::ERROR;
                    
                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @jsulm said in From Ubuntu to Windows: Syntax Error C2059 / C2143:

                    But then you will need to qualify using enum name:
                    MSG_TYPE::ERROR;

                    Again: this will not help. It's a define in wingdi.h:

                    /* Region Flags */
                    #define ERROR               0
                    #define NULLREGION          1
                    #define SIMPLEREGION        2
                    #define COMPLEXREGION       3
                    #define RGN_ERROR ERROR
                    

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

                    1 Reply Last reply
                    3
                    • hskoglundH Offline
                      hskoglundH Offline
                      hskoglund
                      wrote on last edited by
                      #14

                      About wingdi.h clobbering the global #define-space, Microsoft usually provides an escape hatch, put this

                      #define NOGDI
                      

                      somewhere before #include windows.h

                      1 Reply Last reply
                      4

                      • Login

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