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
QtWS25 Last Chance

From Ubuntu to Windows: Syntax Error C2059 / C2143

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 8 Posters 1.5k Views
  • 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
    15 Jul 2020, 19:33

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

    J Offline
    J Offline
    JonB
    wrote on 15 Jul 2020, 19:38 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
    • F Offline
      F Offline
      fcarney
      wrote on 15 Jul 2020, 20:03 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
      • C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 15 Jul 2020, 20:23 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 1 Reply Last reply 16 Jul 2020, 05:32
        5
        • F fem_dev
          15 Jul 2020, 19:33

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 16 Jul 2020, 05:29 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

          C 1 Reply Last reply 16 Jul 2020, 15:40
          2
          • C Christian Ehrlicher
            15 Jul 2020, 20:23

            @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 Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 16 Jul 2020, 05:32 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.

            J 1 Reply Last reply 16 Jul 2020, 12:49
            3
            • J J.Hilk
              16 Jul 2020, 05:32

              @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

              J Offline
              J Offline
              JonB
              wrote on 16 Jul 2020, 12:49 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
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 16 Jul 2020, 12:57 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.

                J 1 Reply Last reply 16 Jul 2020, 15:34
                0
                • M mrjj
                  16 Jul 2020, 12:57

                  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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 16 Jul 2020, 15:34 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
                  • J jsulm
                    16 Jul 2020, 05:29

                    @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;
                    
                    C Online
                    C Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 16 Jul 2020, 15:40 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
                    • H Offline
                      H Offline
                      hskoglund
                      wrote on 16 Jul 2020, 16:16 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

                      14/14

                      16 Jul 2020, 16:16

                      • Login

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