Cout in a loop for QLabel Widgets
-
wrote on 10 Dec 2021, 09:13 last edited by Swati777999 12 Oct 2021, 09:25
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
Name2I 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?
-
I want to show something like this:
Name 1
Name 2
Name 3
etc.Names[ii] = new QLabel(QString("Name %1").arg(ii));
-
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
Name2I 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?
@Swati777999 said in Cout in a loop for QLabel Widgets:
QLabel Names[ii] = new QLabel("Name" ,ii);
Names[ii] = new QLabel("Name" ,ii);
-
@Swati777999 said in Cout in a loop for QLabel Widgets:
QLabel Names[ii] = new QLabel("Name" ,ii);
Names[ii] = new QLabel("Name" ,ii);
wrote on 10 Dec 2021, 09:25 last edited by@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.
-
@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.
@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? -
@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?wrote on 10 Dec 2021, 09:42 last edited byI want to show something like this:
Name 1
Name 2
Name 3
etc. -
I want to show something like this:
Name 1
Name 2
Name 3
etc.Names[ii] = new QLabel(QString("Name %1").arg(ii));
-
@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?wrote on 10 Dec 2021, 09:44 last edited by Swati777999 12 Oct 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? -
@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?@Swati777999 said in Cout in a loop for QLabel Widgets:
Is there any other way to achieve it?
Please read my post above
-
Names[ii] = new QLabel(QString("Name %1").arg(ii));
wrote on 10 Dec 2021, 09:49 last edited by@jsulm said in Cout in a loop for QLabel Widgets:
Names[ii] = new QLabel(QString("Name %1").arg(ii));
Works perfectly! Thanks.
4/9