Want to execute a QString statement, which has the last part as integer variable

95 views Asked by At

The statement is:

int nmbr;
QString strngs;

for( nmbr = 62; nmbr <65; nmbr++)
{
   strngs=(QString)"qDebug()<<(QString)ui->label_"+QString::number(nmbr)+"->text();";
}

Actually I want to access QLabels, a lot of them and extract their text for using at some other place.

Thanks!

1

There are 1 answers

0
George Y. On BEST ANSWER

Are you trying to get the text from a lot of QLabels of a current widget?

Then you'd better do something like that:

for( int nmbr = 62; nmbr <65; nmbr++)
{
    QString labelname = QString("label_%1") .arg( nmbr );
    QLabel * label = findChild<QLabel*>( labelname );

    if ( label )
        qDebug() << label->text();
}

Is this what you're looking for?