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. How to get the name of parameters ?
Forum Updated to NodeBB v4.3 + New Features

How to get the name of parameters ?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 1.3k 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.
  • S Offline
    S Offline
    sonichy
    wrote on 30 Nov 2018, 02:58 last edited by
    #1

    I need to print the name of parameters.

    QStringList player1;
    player1 << "a" << "a" << "b" << "c";
    duplicateCount(player1);
    void MainWindow::duplicateCount(QStringList stringList)
    {
        qDebug() << stringList.name << stringList;
    }
    

    Output:
    player1 ("a" , "a" , "b" , "c")

    https://github.com/sonichy

    D J 2 Replies Last reply 30 Nov 2018, 04:53
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 30 Nov 2018, 04:28 last edited by
      #2

      Do you want fetch a, b, c etc separately ? What do u mean by get the name of parameters ?Did you check on stringList.at(index) function ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • S sonichy
        30 Nov 2018, 02:58

        I need to print the name of parameters.

        QStringList player1;
        player1 << "a" << "a" << "b" << "c";
        duplicateCount(player1);
        void MainWindow::duplicateCount(QStringList stringList)
        {
            qDebug() << stringList.name << stringList;
        }
        

        Output:
        player1 ("a" , "a" , "b" , "c")

        D Offline
        D Offline
        Devopia53
        wrote on 30 Nov 2018, 04:53 last edited by
        #3

        @sonichy

        In that case, you can use a macro. like this:

        #define PRINT_VAR_NAME(name) printVarName(#name, (name))
        void printVarName(const QString &name, const QStringList &list)
        {
            qDebug() << name << list;
        }
        [...]
        QStringList player1;
        player1 << "a" << "a" << "b" << "c";
        PRINT_VAR_NAME(player1);
        
        1 Reply Last reply
        1
        • S sonichy
          30 Nov 2018, 02:58

          I need to print the name of parameters.

          QStringList player1;
          player1 << "a" << "a" << "b" << "c";
          duplicateCount(player1);
          void MainWindow::duplicateCount(QStringList stringList)
          {
              qDebug() << stringList.name << stringList;
          }
          

          Output:
          player1 ("a" , "a" , "b" , "c")

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 30 Nov 2018, 05:50 last edited by
          #4

          @sonichy

          void MainWindow::duplicateCount(QStringList stringList)
          {
              qDebug() << Q_FUNC_INFO << stringList;
          }
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 1 Dec 2018, 01:45
          1
          • J jsulm
            30 Nov 2018, 05:50

            @sonichy

            void MainWindow::duplicateCount(QStringList stringList)
            {
                qDebug() << Q_FUNC_INFO << stringList;
            }
            
            S Offline
            S Offline
            sonichy
            wrote on 1 Dec 2018, 01:45 last edited by
            #5

            @jsulm said in How to get the name of parameters ?:
            Q_FUNC_INFO just print:

            void MainWindow::duplicateCount(QStringList)
            

            But I want to print var name: player1.

            https://github.com/sonichy

            J 1 Reply Last reply 1 Dec 2018, 11:00
            0
            • S sonichy
              1 Dec 2018, 01:45

              @jsulm said in How to get the name of parameters ?:
              Q_FUNC_INFO just print:

              void MainWindow::duplicateCount(QStringList)
              

              But I want to print var name: player1.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 1 Dec 2018, 11:00 last edited by
              #6

              @sonichy said in How to get the name of parameters ?:

              But I want to print var name: player1.

              You cannot do that in C++, because variable names are removed when your code is compiled.

              You can pass the name as a separate parameter:

              void MainWindow::duplicateCount(const QStringList &stringList, const QString &name)
              {
                  qDebug() << name << stringList;
              }
              

              Anyway, why do you need to know the name?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              S 1 Reply Last reply 2 Dec 2018, 03:34
              1
              • J JKSH
                1 Dec 2018, 11:00

                @sonichy said in How to get the name of parameters ?:

                But I want to print var name: player1.

                You cannot do that in C++, because variable names are removed when your code is compiled.

                You can pass the name as a separate parameter:

                void MainWindow::duplicateCount(const QStringList &stringList, const QString &name)
                {
                    qDebug() << name << stringList;
                }
                

                Anyway, why do you need to know the name?

                S Offline
                S Offline
                sonichy
                wrote on 2 Dec 2018, 03:34 last edited by
                #7

                @JKSH It seems like SLOT needs sender().

                https://github.com/sonichy

                J 1 Reply Last reply 2 Dec 2018, 13:03
                0
                • S sonichy
                  2 Dec 2018, 03:34

                  @JKSH It seems like SLOT needs sender().

                  J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 2 Dec 2018, 13:03 last edited by
                  #8

                  @sonichy said in How to get the name of parameters ?:

                  @JKSH It seems like SLOT needs sender().

                  Sorry, what do you mean?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0

                  1/8

                  30 Nov 2018, 02:58

                  • Login

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