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. Cout in a loop for QLabel Widgets
Forum Updated to NodeBB v4.3 + New Features

Cout in a loop for QLabel Widgets

Scheduled Pinned Locked Moved Solved General and Desktop
qmaploopcout labelqlabel
9 Posts 2 Posters 1.2k 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by Swati777999
    #1

    Hi All,

    I want to do something like the following:

    int n=10;
    QMap <int, QLabel*>Names;
    for (int ii=0;ii<n;ii++)
    
    { Names[ii] = new QLabel("Name" ,ii);
    }
    

    Output : Name1
    Name2

    I know that Names[ii] = new QLabel("Name" ,ii) ; is a wrong syntax , I want to get the result like
    cout << "Name" <<ii ;

    How can it be achieved in Qt?

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    jsulmJ 1 Reply Last reply
    0
    • Swati777999S Swati777999

      @jsulm

      I want to show something like this:
      Name 1
      Name 2
      Name 3
      etc.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @Swati777999

      Names[ii] = new QLabel(QString("Name %1").arg(ii));
      

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

      Swati777999S 1 Reply Last reply
      3
      • Swati777999S Swati777999

        Hi All,

        I want to do something like the following:

        int n=10;
        QMap <int, QLabel*>Names;
        for (int ii=0;ii<n;ii++)
        
        { Names[ii] = new QLabel("Name" ,ii);
        }
        

        Output : Name1
        Name2

        I know that Names[ii] = new QLabel("Name" ,ii) ; is a wrong syntax , I want to get the result like
        cout << "Name" <<ii ;

        How can it be achieved in Qt?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Swati777999 said in Cout in a loop for QLabel Widgets:

        QLabel Names[ii] = new QLabel("Name" ,ii);

        Names[ii] = new QLabel("Name" ,ii);
        

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

        Swati777999S 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Swati777999 said in Cout in a loop for QLabel Widgets:

          QLabel Names[ii] = new QLabel("Name" ,ii);

          Names[ii] = new QLabel("Name" ,ii);
          
          Swati777999S Offline
          Swati777999S Offline
          Swati777999
          wrote on last edited by
          #3

          @jsulm said in Cout in a loop for QLabel Widgets:

          @Swati777999 said in Cout in a loop for QLabel Widgets:

          QLabel Names[ii] = new QLabel("Name" ,ii);

          Names[ii] = new QLabel("Name" ,ii);
          

          This syntax gives me error.

          “ In order to be irreplaceable, one must always be different” – Coco Chanel

          jsulmJ 1 Reply Last reply
          0
          • Swati777999S Swati777999

            @jsulm said in Cout in a loop for QLabel Widgets:

            @Swati777999 said in Cout in a loop for QLabel Widgets:

            QLabel Names[ii] = new QLabel("Name" ,ii);

            Names[ii] = new QLabel("Name" ,ii);
            

            This syntax gives me error.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Swati777999 said in Cout in a loop for QLabel Widgets:

            This syntax gives me error.

            Of course. Please learn to read documentation (https://doc.qt.io/qt-5/qlabel.html)!
            There is no such constructor in QLabel.
            What do you actually want to do?
            Do you want to show the number (ii) in the label?

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

            Swati777999S 2 Replies Last reply
            0
            • jsulmJ jsulm

              @Swati777999 said in Cout in a loop for QLabel Widgets:

              This syntax gives me error.

              Of course. Please learn to read documentation (https://doc.qt.io/qt-5/qlabel.html)!
              There is no such constructor in QLabel.
              What do you actually want to do?
              Do you want to show the number (ii) in the label?

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on last edited by
              #5

              @jsulm

              I want to show something like this:
              Name 1
              Name 2
              Name 3
              etc.

              “ In order to be irreplaceable, one must always be different” – Coco Chanel

              jsulmJ 1 Reply Last reply
              0
              • Swati777999S Swati777999

                @jsulm

                I want to show something like this:
                Name 1
                Name 2
                Name 3
                etc.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Swati777999

                Names[ii] = new QLabel(QString("Name %1").arg(ii));
                

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

                Swati777999S 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @Swati777999 said in Cout in a loop for QLabel Widgets:

                  This syntax gives me error.

                  Of course. Please learn to read documentation (https://doc.qt.io/qt-5/qlabel.html)!
                  There is no such constructor in QLabel.
                  What do you actually want to do?
                  Do you want to show the number (ii) in the label?

                  Swati777999S Offline
                  Swati777999S Offline
                  Swati777999
                  wrote on last edited by Swati777999
                  #7

                  @jsulm said in Cout in a loop for QLabel Widgets:

                  @Swati777999 said in Cout in a loop for QLabel Widgets:

                  This syntax gives me error.

                  Of course. Please learn to read documentation (https://doc.qt.io/qt-5/qlabel.html)!

                  Yes, that's the reason why I've specifically mentioned it in my post. There's no such declaration in label for the output of Name ii. Is there any other way to achieve it?

                  “ In order to be irreplaceable, one must always be different” – Coco Chanel

                  jsulmJ 1 Reply Last reply
                  0
                  • Swati777999S Swati777999

                    @jsulm said in Cout in a loop for QLabel Widgets:

                    @Swati777999 said in Cout in a loop for QLabel Widgets:

                    This syntax gives me error.

                    Of course. Please learn to read documentation (https://doc.qt.io/qt-5/qlabel.html)!

                    Yes, that's the reason why I've specifically mentioned it in my post. There's no such declaration in label for the output of Name ii. Is there any other way to achieve it?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @Swati777999 said in Cout in a loop for QLabel Widgets:

                    Is there any other way to achieve it?

                    Please read my post above

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

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Swati777999

                      Names[ii] = new QLabel(QString("Name %1").arg(ii));
                      
                      Swati777999S Offline
                      Swati777999S Offline
                      Swati777999
                      wrote on last edited by
                      #9

                      @jsulm said in Cout in a loop for QLabel Widgets:

                      @Swati777999

                      Names[ii] = new QLabel(QString("Name %1").arg(ii));
                      

                      Works perfectly! Thanks.

                      “ In order to be irreplaceable, one must always be different” – Coco Chanel

                      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