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

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

    tomasz3dkT joeQJ R 3 Replies Last reply
    0
    • S shashi prasad

      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

      tomasz3dkT Offline
      tomasz3dkT Offline
      tomasz3dk
      wrote on last edited by
      #2

      @shashi-prasad Q_UNUSED

      1 Reply Last reply
      2
      • S shashi prasad

        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

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by joeQ
        #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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

            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 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              1
              • SGaistS SGaist

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

                • Login

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