Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Warning in C++ QT creator Linux
QtWS25 Last Chance

Warning in C++ QT creator Linux

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 5 Posters 2.9k 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.
  • S Offline
    S Offline
    shashi prasad
    wrote on 10 Aug 2017, 07:01 last edited by
    #1

    Hi,
    i used function as

    int fun(int x,int y){

    return 0;
    }

    i did not use variable x and y.

    but getting warning as
    warning: unused parameter 'x' [-Wunused-parameter]

    i don not want to remove this variable from this function.

    please suggest me how to resolve this issue.

    Thanks
    Shashi

    T J R 3 Replies Last reply 10 Aug 2017, 07:08
    0
    • S shashi prasad
      10 Aug 2017, 07:01

      Hi,
      i used function as

      int fun(int x,int y){

      return 0;
      }

      i did not use variable x and y.

      but getting warning as
      warning: unused parameter 'x' [-Wunused-parameter]

      i don not want to remove this variable from this function.

      please suggest me how to resolve this issue.

      Thanks
      Shashi

      T Offline
      T Offline
      tomasz3dk
      wrote on 10 Aug 2017, 07:08 last edited by
      #2

      @shashi-prasad Q_UNUSED

      1 Reply Last reply
      2
      • S shashi prasad
        10 Aug 2017, 07:01

        Hi,
        i used function as

        int fun(int x,int y){

        return 0;
        }

        i did not use variable x and y.

        but getting warning as
        warning: unused parameter 'x' [-Wunused-parameter]

        i don not want to remove this variable from this function.

        please suggest me how to resolve this issue.

        Thanks
        Shashi

        J Offline
        J Offline
        joeQ
        wrote on 10 Aug 2017, 07:10 last edited by joeQ 8 Oct 2017, 07:11
        #3

        @shashi-prasad hi, friend, welcome.

        you can reference Q_UNUSED

        #define UNUSED(x) (void)x;
        
        int fun(int x,int y){
        UNUSED(x);
        UNUSED(y);
        return 0;
        }
        

        or just said

        int fun(int ,int ){
        return 0;
        }
        ``
        
        you can add x,y when you want to use x,y. at any time.

        Just do it!

        1 Reply Last reply
        3
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Aug 2017, 07:10 last edited by
          #4

          Hi,

          An alternative to the good solution proposed by @tomasz3dk: comment the name of the parameters.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S shashi prasad
            10 Aug 2017, 07:01

            Hi,
            i used function as

            int fun(int x,int y){

            return 0;
            }

            i did not use variable x and y.

            but getting warning as
            warning: unused parameter 'x' [-Wunused-parameter]

            i don not want to remove this variable from this function.

            please suggest me how to resolve this issue.

            Thanks
            Shashi

            R Offline
            R Offline
            Rohith
            wrote on 10 Aug 2017, 07:11 last edited by
            #5

            @shashi-prasad

            Hi Shashi - prasad,

            You are seeing the warning because, you are not using the variable parameter you are just passing value.
            If you even print the value of variable with the help of cout or qDebug i hope you will not see the warning.

            More over it's just a warning, most of the cases we can ignore Warnings.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 10 Aug 2017, 07:18 last edited by
              #6

              @Rohith never ignore warnings blindly. If there's a warning there's a reason for it and you should always do your best to fix them because some innocuous looking warnings might be source of strange errors.

              See here for an example.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              R 1 Reply Last reply 10 Aug 2017, 07:26
              1
              • S SGaist
                10 Aug 2017, 07:18

                @Rohith never ignore warnings blindly. If there's a warning there's a reason for it and you should always do your best to fix them because some innocuous looking warnings might be source of strange errors.

                See here for an example.

                R Offline
                R Offline
                Rohith
                wrote on 10 Aug 2017, 07:26 last edited by
                #7

                @SGaist

                • More over it's just a warning, most of the cases we can ignore Warnings.

                Thanks for sharing the link and my intention in mention the above words are not to totally ignore the warnings there are cases which can be ignored and which can't be ignored. I was unable to explain perfectly in post any way thanks for correcting my mistake.

                1 Reply Last reply
                0

                3/7

                10 Aug 2017, 07:10

                • Login

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