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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on 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 jsulmJ 2 Replies Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on 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
      • sonichyS sonichy

        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 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
        • sonichyS sonichy

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          sonichyS 1 Reply Last reply
          1
          • jsulmJ jsulm

            @sonichy

            void MainWindow::duplicateCount(QStringList stringList)
            {
                qDebug() << Q_FUNC_INFO << stringList;
            }
            
            sonichyS Offline
            sonichyS Offline
            sonichy
            wrote on 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

            JKSHJ 1 Reply Last reply
            0
            • sonichyS sonichy

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

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on 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

              sonichyS 1 Reply Last reply
              1
              • JKSHJ JKSH

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

                sonichyS Offline
                sonichyS Offline
                sonichy
                wrote on last edited by
                #7

                @JKSH It seems like SLOT needs sender().

                https://github.com/sonichy

                JKSHJ 1 Reply Last reply
                0
                • sonichyS sonichy

                  @JKSH It seems like SLOT needs sender().

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on 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

                  • Login

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