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. error: C2057: expected constant expression
Forum Updated to NodeBB v4.3 + New Features

error: C2057: expected constant expression

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 5 Posters 8.1k Views 3 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.
  • D Dr. No

    @kenchan I've tried a older version, 5.5.0 just to see if it could work. The error messages edited on my post (part of update) I copied from there. Hence the two diferente versions. But it did not work with either version and result in same error.

    K Offline
    K Offline
    kenchan
    wrote on last edited by kenchan
    #7

    @Dr.-No well yes, but the higher compiler version might still be the issue in both cases.
    if you scroll to the bottom of the linked page i gave you it shows the compatible tools for each Qt 5 version.

    D 1 Reply Last reply
    2
    • K kenchan

      @Dr.-No well yes, but the higher compiler version might still be the issue in both cases.
      if you scroll to the bottom of the linked page i gave you it shows the compatible tools for each Qt 5 version.

      D Offline
      D Offline
      Dr. No
      wrote on last edited by
      #8

      @kenchan So for Qt 5.7.1, the cl is Windows-Windows_10-x86-MSVC2015 I must use this visual studio 2015, right?

      I've tried it already, download a 6gb isntallation and change my bat to the following:

      call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
      "C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe"
      
      and I get the same error...
      
      kshegunovK 1 Reply Last reply
      0
      • D Dr. No

        @kenchan So for Qt 5.7.1, the cl is Windows-Windows_10-x86-MSVC2015 I must use this visual studio 2015, right?

        I've tried it already, download a 6gb isntallation and change my bat to the following:

        call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
        "C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe"
        
        and I get the same error...
        
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #9

        I think you're doing the thing backwards.
        See what visual studio you already have (from the first post it seems VS2017- C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\...), then from the Qt maintenance tool select a Qt version that provides you a binary distribution for that compiler, i.e. Qt >= 5.9 msvc2017-x86 and install it, possibly install the 64 bit binaries msvc2017-x86_x64 as well.
        Then start Qt Creator (no need for call ....) and configure the kit for that Qt version and this compiler.
        To get the debugger you will also need to install CDB from MS debugging tools package.

        Read and abide by the Qt Code of Conduct

        D 1 Reply Last reply
        1
        • kshegunovK kshegunov

          I think you're doing the thing backwards.
          See what visual studio you already have (from the first post it seems VS2017- C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\...), then from the Qt maintenance tool select a Qt version that provides you a binary distribution for that compiler, i.e. Qt >= 5.9 msvc2017-x86 and install it, possibly install the 64 bit binaries msvc2017-x86_x64 as well.
          Then start Qt Creator (no need for call ....) and configure the kit for that Qt version and this compiler.
          To get the debugger you will also need to install CDB from MS debugging tools package.

          D Offline
          D Offline
          Dr. No
          wrote on last edited by
          #10

          @kshegunov I had VS 2017 instealled already before I need to use MSVC++ compiler with Qt. I was using mingw before but I needed to switch to MSVC++ because I have to use a debugging library that only supports MSVC++ debugg symbols. So I installed Qt with MSVC++ when I went to compile, that error begun. I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.

          kshegunovK 1 Reply Last reply
          0
          • D Dr. No

            @kshegunov I had VS 2017 instealled already before I need to use MSVC++ compiler with Qt. I was using mingw before but I needed to switch to MSVC++ because I have to use a debugging library that only supports MSVC++ debugg symbols. So I installed Qt with MSVC++ when I went to compile, that error begun. I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #11

            @Dr.-No said in error: C2057: expected constant expression:

            So I installed Qt with MSVC++

            Please explain exactly what you did. There's no Qt with MSVC, there're a number of distributions of the Qt library compiled with different versions of the MS compiler, and what compiler you have will govern which exact distribution of Qt you will need.

            I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.

            You can start Qt Creator without ever needing to have an installed compiler. I don't understand why you call the bat script before starting the IDE. What you need is, as I wrote, to configure the toolchain for your compiler, not start the IDE with the visual studio environment.

            Read and abide by the Qt Code of Conduct

            D 1 Reply Last reply
            0
            • D Offline
              D Offline
              Dr. No
              wrote on last edited by
              #12
              This post is deleted!
              1 Reply Last reply
              0
              • kshegunovK kshegunov

                @Dr.-No said in error: C2057: expected constant expression:

                So I installed Qt with MSVC++

                Please explain exactly what you did. There's no Qt with MSVC, there're a number of distributions of the Qt library compiled with different versions of the MS compiler, and what compiler you have will govern which exact distribution of Qt you will need.

                I use call to call the vcvarsall.bat file within my batch script, without the bat doesn't work.

                You can start Qt Creator without ever needing to have an installed compiler. I don't understand why you call the bat script before starting the IDE. What you need is, as I wrote, to configure the toolchain for your compiler, not start the IDE with the visual studio environment.

                D Offline
                D Offline
                Dr. No
                wrote on last edited by
                #13

                @kshegunov I downloaded the Qt Creator from this link, installed, opened my project but when I went to compile I got a cl not found error. So I search on google about the error and found that I should run vcvarsall.bat x86 to set up the needed varialbles. I did that and went to compile again, this time, the cl error was gone but then I got the error, title of this thread. Does make sense to configure the toolchain within the IDE but it didn't work. In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.

                kshegunovK 1 Reply Last reply
                0
                • D Dr. No

                  @kshegunov I downloaded the Qt Creator from this link, installed, opened my project but when I went to compile I got a cl not found error. So I search on google about the error and found that I should run vcvarsall.bat x86 to set up the needed varialbles. I did that and went to compile again, this time, the cl error was gone but then I got the error, title of this thread. Does make sense to configure the toolchain within the IDE but it didn't work. In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #14

                  @Dr.-No said in error: C2057: expected constant expression:

                  In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.

                  I haven't seen or done that, it may work or not, can't say. What I usually do is follow the Qt Creator manual on configuring the compilers and just put the VC init script in the proper box, that is if creator has failed to detect the compiler automatically ...

                  Read and abide by the Qt Code of Conduct

                  D 1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    @Dr.-No said in error: C2057: expected constant expression:

                    In fact, I saw alot of people running that script before using Qt Creator IDE, hence the need of this bat.

                    I haven't seen or done that, it may work or not, can't say. What I usually do is follow the Qt Creator manual on configuring the compilers and just put the VC init script in the proper box, that is if creator has failed to detect the compiler automatically ...

                    D Offline
                    D Offline
                    Dr. No
                    wrote on last edited by
                    #15

                    @kshegunov Qt doesn't fail to detect the compiler but it give the cl command not found error, like this: https://stackoverflow.com/questions/8800361/cl-is-not-recognized-as-an-internal-or-external-command

                    The only thing which makes the error go away was that VS batch script to set up the proper paths in the system environment's variables.

                    K 1 Reply Last reply
                    0
                    • D Dr. No

                      @kshegunov Qt doesn't fail to detect the compiler but it give the cl command not found error, like this: https://stackoverflow.com/questions/8800361/cl-is-not-recognized-as-an-internal-or-external-command

                      The only thing which makes the error go away was that VS batch script to set up the proper paths in the system environment's variables.

                      K Offline
                      K Offline
                      kenchan
                      wrote on last edited by
                      #16

                      @Dr.-No So is everything now good to go for you then?

                      D 1 Reply Last reply
                      0
                      • K kenchan

                        @Dr.-No So is everything now good to go for you then?

                        D Offline
                        D Offline
                        Dr. No
                        wrote on last edited by
                        #17

                        @kenchan No. I'm with same error... I solved the cl error before create this thread. Once this compiled, I got expected constant expression error.

                        K 1 Reply Last reply
                        0
                        • D Dr. No

                          @kenchan No. I'm with same error... I solved the cl error before create this thread. Once this compiled, I got expected constant expression error.

                          K Offline
                          K Offline
                          kenchan
                          wrote on last edited by
                          #18

                          @Dr.-No Oh dear :-(.
                          OK so just to clarify where you are now when you get this error...
                          which Qt are you now building against?
                          which version of Visual Studio are you now building with?
                          are you using the QT Creator IDE to build the project?
                          are you using Visual Studio IDE to build the project?

                          D 1 Reply Last reply
                          0
                          • K kenchan

                            @Dr.-No Oh dear :-(.
                            OK so just to clarify where you are now when you get this error...
                            which Qt are you now building against?
                            which version of Visual Studio are you now building with?
                            are you using the QT Creator IDE to build the project?
                            are you using Visual Studio IDE to build the project?

                            D Offline
                            D Offline
                            Dr. No
                            wrote on last edited by
                            #19

                            @kenchan This is really bad, I have no idea why I'm getting this error. :( I'm downloading 5.10.1 to see if it works. Hope it's something has been fixed.

                            which Qt are you now building against?

                            Qt creator 4.2.0 and Qt 5.7.1

                            which version of Visual Studio are you now building with?

                            Visual studio community 2017

                            are you using the QT Creator IDE to build the project?

                            yes, as mentioned, version 4.2.0

                            are you using Visual Studio IDE to build the project?

                            nope... as it Qt project (written using mingw) I have only used Qt creator IDE.

                            K 1 Reply Last reply
                            0
                            • D Dr. No

                              @kenchan This is really bad, I have no idea why I'm getting this error. :( I'm downloading 5.10.1 to see if it works. Hope it's something has been fixed.

                              which Qt are you now building against?

                              Qt creator 4.2.0 and Qt 5.7.1

                              which version of Visual Studio are you now building with?

                              Visual studio community 2017

                              are you using the QT Creator IDE to build the project?

                              yes, as mentioned, version 4.2.0

                              are you using Visual Studio IDE to build the project?

                              nope... as it Qt project (written using mingw) I have only used Qt creator IDE.

                              K Offline
                              K Offline
                              kenchan
                              wrote on last edited by
                              #20

                              @Dr.-No Thank you for clarifying that :-). Please post back here the results when using Qt 5.10.1.
                              I might have a Qt 5.7.1 around here somewhere :-)

                              D 1 Reply Last reply
                              0
                              • K kenchan

                                @Dr.-No Thank you for clarifying that :-). Please post back here the results when using Qt 5.10.1.
                                I might have a Qt 5.7.1 around here somewhere :-)

                                D Offline
                                D Offline
                                Dr. No
                                wrote on last edited by Dr. No
                                #21

                                @kenchan on the "issues" window within Qt Creator IDE, the error is:

                                C:\Qt-MSVC\Qt5.7.1\5.7\msvc2015\include\QtCore\qmetatype.h:945: error: expected constant expression
                                

                                looking in the compiler output window, I can see those erros too:

                                qmetatype.h:944: see
                                reference to class template instantiation
                                'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,std::random_access_iterator_tag>'
                                being compiled
                                qmetatype.h:1015: see
                                reference to class template instantiation
                                'QtMetaTypePrivate::ContainerAPI<T>' being compiled with [
                                T=QVariantList ] qvariant.h:711: see
                                reference to function template instantiation
                                'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl<QVariantList>(const
                                T *)' being compiled with [
                                T=QVariantList ]
                                

                                Soon as I try Qt 5.10.1 I'll post the results here.

                                EDIT

                                This is the line of error qmetatype.h:945:

                                { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                

                                from:

                                struct CapabilitiesImpl<T, std::random_access_iterator_tag>
                                { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                
                                K kshegunovK 2 Replies Last reply
                                0
                                • D Dr. No

                                  @kenchan on the "issues" window within Qt Creator IDE, the error is:

                                  C:\Qt-MSVC\Qt5.7.1\5.7\msvc2015\include\QtCore\qmetatype.h:945: error: expected constant expression
                                  

                                  looking in the compiler output window, I can see those erros too:

                                  qmetatype.h:944: see
                                  reference to class template instantiation
                                  'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,std::random_access_iterator_tag>'
                                  being compiled
                                  qmetatype.h:1015: see
                                  reference to class template instantiation
                                  'QtMetaTypePrivate::ContainerAPI<T>' being compiled with [
                                  T=QVariantList ] qvariant.h:711: see
                                  reference to function template instantiation
                                  'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl<QVariantList>(const
                                  T *)' being compiled with [
                                  T=QVariantList ]
                                  

                                  Soon as I try Qt 5.10.1 I'll post the results here.

                                  EDIT

                                  This is the line of error qmetatype.h:945:

                                  { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                  

                                  from:

                                  struct CapabilitiesImpl<T, std::random_access_iterator_tag>
                                  { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                  
                                  K Offline
                                  K Offline
                                  kenchan
                                  wrote on last edited by
                                  #22

                                  @Dr.-No Hello again.
                                  I had the same Qt package you have and hacked a kit to use the Vs 2017 compiler (v19.13.26129).
                                  I built a simple widget project with a QMainWindow, did not see any issues.
                                  I found this old bug report which looks relevant to the issue you saw.
                                  I added the code to reproduce that in my test app but still did not see any issues when compiling...
                                  Not sure what more I can do to help you with on that one :-(.
                                  wishing you Good Luck with Qt 5.10.1

                                  D 1 Reply Last reply
                                  0
                                  • D Dr. No

                                    @kenchan on the "issues" window within Qt Creator IDE, the error is:

                                    C:\Qt-MSVC\Qt5.7.1\5.7\msvc2015\include\QtCore\qmetatype.h:945: error: expected constant expression
                                    

                                    looking in the compiler output window, I can see those erros too:

                                    qmetatype.h:944: see
                                    reference to class template instantiation
                                    'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,std::random_access_iterator_tag>'
                                    being compiled
                                    qmetatype.h:1015: see
                                    reference to class template instantiation
                                    'QtMetaTypePrivate::ContainerAPI<T>' being compiled with [
                                    T=QVariantList ] qvariant.h:711: see
                                    reference to function template instantiation
                                    'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl<QVariantList>(const
                                    T *)' being compiled with [
                                    T=QVariantList ]
                                    

                                    Soon as I try Qt 5.10.1 I'll post the results here.

                                    EDIT

                                    This is the line of error qmetatype.h:945:

                                    { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                    

                                    from:

                                    struct CapabilitiesImpl<T, std::random_access_iterator_tag>
                                    { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
                                    
                                    kshegunovK Offline
                                    kshegunovK Offline
                                    kshegunov
                                    Moderators
                                    wrote on last edited by kshegunov
                                    #23

                                    As I said this line is valid C++, it doesn't even require anything c++11 related.
                                    I continue to believe that the error is cause by a misconfiguration of the IDE, which you should fix by configuring the kit (i.e. compiler and Qt distribution). Information is aplenty - reading the creator manual (sourced in previous post) and searching the forums here should be just enough.

                                    Read and abide by the Qt Code of Conduct

                                    D 1 Reply Last reply
                                    3
                                    • K kenchan

                                      @Dr.-No Hello again.
                                      I had the same Qt package you have and hacked a kit to use the Vs 2017 compiler (v19.13.26129).
                                      I built a simple widget project with a QMainWindow, did not see any issues.
                                      I found this old bug report which looks relevant to the issue you saw.
                                      I added the code to reproduce that in my test app but still did not see any issues when compiling...
                                      Not sure what more I can do to help you with on that one :-(.
                                      wishing you Good Luck with Qt 5.10.1

                                      D Offline
                                      D Offline
                                      Dr. No
                                      wrote on last edited by
                                      #24

                                      @kenchan So I was trying luck with Qt 5.10.1. With mingw32 it compiled fine (the project was originally written with mingw32). But with both MSVC2015 and MS2017 I got that error. I haven't change a single line in that source code. It's the exact same source code but with MSVC it give that error. I need to use that compiler because the debugging library I mentioned which only works with MSVC compiler.

                                      1 Reply Last reply
                                      0
                                      • kshegunovK kshegunov

                                        As I said this line is valid C++, it doesn't even require anything c++11 related.
                                        I continue to believe that the error is cause by a misconfiguration of the IDE, which you should fix by configuring the kit (i.e. compiler and Qt distribution). Information is aplenty - reading the creator manual (sourced in previous post) and searching the forums here should be just enough.

                                        D Offline
                                        D Offline
                                        Dr. No
                                        wrote on last edited by
                                        #25

                                        @kshegunov I'm trying to find the source of misconfiguration which I also believe is the reason of the error. Without running the vcvarsall.bat bar, the compilation with MSVC fail to find the rc executable. All the compilers are properly detected by Qt Creator IDE but it fails to compile, for example, didn't find rc or cl executable. I don't know where check... if it's a PATH missing. I've removed VS2015 affraid of some conflict with VC2017 remove all but the Qt 5.10. And nothing Works.

                                        aha_1980A 1 Reply Last reply
                                        0
                                        • D Dr. No

                                          @kshegunov I'm trying to find the source of misconfiguration which I also believe is the reason of the error. Without running the vcvarsall.bat bar, the compilation with MSVC fail to find the rc executable. All the compilers are properly detected by Qt Creator IDE but it fails to compile, for example, didn't find rc or cl executable. I don't know where check... if it's a PATH missing. I've removed VS2015 affraid of some conflict with VC2017 remove all but the Qt 5.10. And nothing Works.

                                          aha_1980A Offline
                                          aha_1980A Offline
                                          aha_1980
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #26

                                          Hi @Dr.-No

                                          We had some requests with missing cl.exe here in the forum (you could search for them), and there is e.g. https://bugreports.qt.io/browse/QTCREATORBUG-17474 (but maybe more).

                                          In short: QtCreator runs the vcvarsXX.bat also, but in some setups this takes very long and times out. There are also solutions out there which hardcode the paths in the bat file that are determined by registry calls otherwise. You could do this too, if you know what you are doing ;)

                                          In any case, the compiler has to match the Qt version and the path to the compiler must be correct. I assume that there is something wrong in your setup, and maybe (most likely) hte error C2057 is just a result of that.

                                          Regards

                                          Qt has to stay free or it will die.

                                          1 Reply Last reply
                                          1

                                          • Login

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