Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Independent Developers
  4. Error C2440 Qt Creator not allowing literals to be passed as "char *"
Forum Updated to NodeBB v4.3 + New Features

Error C2440 Qt Creator not allowing literals to be passed as "char *"

Scheduled Pinned Locked Moved Solved Independent Developers
qt creatorvisual studio
9 Posts 4 Posters 4.2k 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.
  • SprezzaturaS Offline
    SprezzaturaS Offline
    Sprezzatura
    wrote on last edited by Sprezzatura
    #1

    (Not sure if this should be posted in "General & Desktop"?)

    We are converting an app from VS2017 to Qt Creator 4.7.0 (Qt 5.11.1). Qt is a bit more stringent. We are getting error C2440 on this type of code, which compiles and runs fine in VS:

    void foo(char *);
    foo ("ABC");
    

    Qt Creator is not allowing it, we have to change to:

    void foo(const char *);
    

    Yes, I know this is the correct way, and it's good for us. However, the code has been working successfully for years in VS, we have a big job ahead of us, and would just like to move on and work on more difficult stuff.

    Can we selectively suppress certain errors? Or tell the compiler to ease up?

    VRoninV 1 Reply Last reply
    0
    • SprezzaturaS Sprezzatura

      (Not sure if this should be posted in "General & Desktop"?)

      We are converting an app from VS2017 to Qt Creator 4.7.0 (Qt 5.11.1). Qt is a bit more stringent. We are getting error C2440 on this type of code, which compiles and runs fine in VS:

      void foo(char *);
      foo ("ABC");
      

      Qt Creator is not allowing it, we have to change to:

      void foo(const char *);
      

      Yes, I know this is the correct way, and it's good for us. However, the code has been working successfully for years in VS, we have a big job ahead of us, and would just like to move on and work on more difficult stuff.

      Can we selectively suppress certain errors? Or tell the compiler to ease up?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @Sprezzatura said in Error C2440 Qt Creator not allowing literals to be passed as "char *":

      Qt is a bit more stringent

      Qt is not a compiler

      We are getting error C2440 on this type of code, which compiles and runs fine in VS

      error C2440 is a MSVC error. Nothing to do with Qt

      Can we selectively suppress certain errors? Or tell the compiler to ease up?

      https://docs.microsoft.com/en-us/cpp/build/reference/zc-strictstrings-disable-string-literal-type-conversion?view=vs-2017

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • SprezzaturaS Offline
        SprezzaturaS Offline
        Sprezzatura
        wrote on last edited by
        #3

        OK, fine. How do I get MSVC to be as lenient, when launched from Qt, as when it runs stand-alone? How do I tell Qt Creator how to pass command line switches to MSVC?

        In other words, why am I getting the error when compiling from within Qt Creator, as when compiling directly from MSVC?

        1 Reply Last reply
        0
        • SprezzaturaS Offline
          SprezzaturaS Offline
          Sprezzatura
          wrote on last edited by
          #4

          I just noticed your link to "/Zc:strictStrings". Excellent news. Now, I just need to know how to pass this on to MSVC?

          aha_1980A 1 Reply Last reply
          0
          • SprezzaturaS Sprezzatura

            I just noticed your link to "/Zc:strictStrings". Excellent news. Now, I just need to know how to pass this on to MSVC?

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

            @Sprezzatura

            Try adding QMAKE_CXXFLAGS += /Zc:strictStrings- to your .pro file (assuming you use qmake)

            I guess /permissive is set and therefore you explicitely need to disable strictStrings.

            Disclaimer: Fix these functions soon, nevertheless. This option is to prevent subtile bugs.

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            3
            • BuckwheatB Offline
              BuckwheatB Offline
              Buckwheat
              wrote on last edited by
              #6

              Hi @Sprezzatura
              If you know it is good to use proper C++ then why would you want to suppress warnings. By suppressing warnings globally you can (and probably will) cause a problem at a later time or someone else maintaining the code could cause a problem.

              It is ALWAYS the best practice to use the highest warning levels and just write clean code. So, in conclusion, it is better to take a small amount of time fixing unsafe code than masking other issues by disabling warnings. If this is a group responsibility, bring it up to the group and plan for further down the road.

              Dave Fileccia

              aha_1980A 1 Reply Last reply
              1
              • BuckwheatB Buckwheat

                Hi @Sprezzatura
                If you know it is good to use proper C++ then why would you want to suppress warnings. By suppressing warnings globally you can (and probably will) cause a problem at a later time or someone else maintaining the code could cause a problem.

                It is ALWAYS the best practice to use the highest warning levels and just write clean code. So, in conclusion, it is better to take a small amount of time fixing unsafe code than masking other issues by disabling warnings. If this is a group responsibility, bring it up to the group and plan for further down the road.

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

                @Buckwheat The problem here is, that it is no warning but an error which blocks the complete build

                I can understand that in this case it's more important to be able to move on first.

                I fully agree, however, that this and other warnings should be treated with respect (I already wrote it above).

                Regards

                Qt has to stay free or it will die.

                BuckwheatB 1 Reply Last reply
                0
                • aha_1980A aha_1980

                  @Buckwheat The problem here is, that it is no warning but an error which blocks the complete build

                  I can understand that in this case it's more important to be able to move on first.

                  I fully agree, however, that this and other warnings should be treated with respect (I already wrote it above).

                  Regards

                  BuckwheatB Offline
                  BuckwheatB Offline
                  Buckwheat
                  wrote on last edited by
                  #8

                  @aha_1980 It is never less important to move on if you have a solution that is the correct solution and want to fish for the less safe and proper. How much time was spent trolling for the answer to the question when he already knew the answer.

                  Dave Fileccia

                  1 Reply Last reply
                  0
                  • SprezzaturaS Offline
                    SprezzaturaS Offline
                    Sprezzatura
                    wrote on last edited by
                    #9

                    @aha_1980, @Buckwheat Thank you very much! This is very helpful.

                    Don't worry, this code has been in production for twenty-five (25) years, and has run on hundreds of thousands of desktops. It was first written with compilers that didn't have 'const'! We'll deal with it when we have a program that runs. It's all good :o)

                    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