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

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.
  • S Offline
    S Offline
    Swati777999
    wrote on 10 Dec 2021, 09:13 last edited by Swati777999 12 Oct 2021, 09:25
    #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

    J 1 Reply Last reply 10 Dec 2021, 09:20
    0
    • S Swati777999
      10 Dec 2021, 09:42

      @jsulm

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

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 10 Dec 2021, 09:43 last edited by
      #6

      @Swati777999

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

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

      S 1 Reply Last reply 10 Dec 2021, 09:49
      3
      • S Swati777999
        10 Dec 2021, 09:13

        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?

        J Online
        J Online
        jsulm
        Lifetime Qt Champion
        wrote on 10 Dec 2021, 09:20 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

        S 1 Reply Last reply 10 Dec 2021, 09:25
        0
        • J jsulm
          10 Dec 2021, 09:20

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

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

          Names[ii] = new QLabel("Name" ,ii);
          
          S Offline
          S Offline
          Swati777999
          wrote on 10 Dec 2021, 09:25 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

          J 1 Reply Last reply 10 Dec 2021, 09:27
          0
          • S Swati777999
            10 Dec 2021, 09:25

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

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 10 Dec 2021, 09:27 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

            S 2 Replies Last reply 10 Dec 2021, 09:42
            0
            • J jsulm
              10 Dec 2021, 09:27

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

              S Offline
              S Offline
              Swati777999
              wrote on 10 Dec 2021, 09:42 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

              J 1 Reply Last reply 10 Dec 2021, 09:43
              0
              • S Swati777999
                10 Dec 2021, 09:42

                @jsulm

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

                J Online
                J Online
                jsulm
                Lifetime Qt Champion
                wrote on 10 Dec 2021, 09:43 last edited by
                #6

                @Swati777999

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

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

                S 1 Reply Last reply 10 Dec 2021, 09:49
                3
                • J jsulm
                  10 Dec 2021, 09:27

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

                  S Offline
                  S Offline
                  Swati777999
                  wrote on 10 Dec 2021, 09:44 last edited by Swati777999 12 Oct 2021, 09:44
                  #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

                  J 1 Reply Last reply 10 Dec 2021, 09:45
                  0
                  • S Swati777999
                    10 Dec 2021, 09:44

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

                    J Online
                    J Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on 10 Dec 2021, 09:45 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
                    • J jsulm
                      10 Dec 2021, 09:43

                      @Swati777999

                      Names[ii] = new QLabel(QString("Name %1").arg(ii));
                      
                      S Offline
                      S Offline
                      Swati777999
                      wrote on 10 Dec 2021, 09:49 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

                      8/9

                      10 Dec 2021, 09:45

                      • Login

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