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.5k 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 Offline
    F Offline
    fem_dev
    wrote on 15 Jul 2020, 18:54 last edited by
    #1

    I just copy my working Qt project from my Ubuntu 20.04 machine to my Windows 10 x64 machine.

    I got two weird compile time errors in my custom header file:

    #ifndef MESSAGE_TYPES_H
    #define MESSAGE_TYPES_H
    
    typedef enum {
        ERROR = -2, // C2059: syntax error: 'constant'
        WARNING = -1,
        STATUS = 0
    } MSG_TYPE; // C2143: syntex error: ';' missing before  '}'
    
    #endif // MESSAGE_TYPES_H
    

    Why it's happening?
    How can I fix it?

    My systems are:
    A)

    • Ubuntu 20.04 x64
    • Qt Creator 4.12.4
    • Qt 5.15
    • GCC 9.3 Compiler x64

    B)

    • Windows 10 x64
    • Qt Creator 4.12.4
    • Qt 5.15
    • MSVC 2019 x64
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 15 Jul 2020, 19:00 last edited by mrjj
      #2

      Hi
      Its a name clash with MSVC 2019
      ERROR is defined already.

      F 1 Reply Last reply 15 Jul 2020, 19:33
      5
      • M mrjj
        15 Jul 2020, 19:00

        Hi
        Its a name clash with MSVC 2019
        ERROR is defined already.

        F Offline
        F Offline
        fem_dev
        wrote on 15 Jul 2020, 19:33 last edited by
        #3

        @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 J 2 Replies Last reply 15 Jul 2020, 19:38
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 15 Jul 2020, 19:37 last edited by
          #4

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

          Why this happen?

          Because it's already defined as @mrjj already told you. It's a #define .

          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
          1
          • 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 Offline
                C Offline
                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 Online
                  J Online
                  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 Offline
                            C Offline
                            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
                            • hskoglundH Offline
                              hskoglundH 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

                              1/14

                              15 Jul 2020, 18:54

                              • Login

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