Cout in a loop for QLabel Widgets
-
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);
@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?I 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?@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));
@jsulm said in Cout in a loop for QLabel Widgets:
Names[ii] = new QLabel(QString("Name %1").arg(ii));
Works perfectly! Thanks.