Click here to Skip to main content
15,887,320 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a working code , I believe the loop is similar to "foreach" syntax.
EDIT
I there a way to add counter / index INTO RANGE
foreach(...) loop ?

I know I can hack it by adding such variable inside the loop...

C++
<pre> 
const QStringList list { "SubWindow terminal    (QMdiArea )",
                            "SubWindow hcitool      (QMdiArea )",
                             "SubWindowbluetoothctl (QMdiArea )",
                             "SubWindow system      (QMdiArea )" };
    QAction *submenu_array[100];
    (int index = 0 ) _
    for ( const auto& i : list )
    {
        (index++_)
        qDebug() << i;


.....

What I have tried:

See hack in the OP
See hack in the OP

See hack in the OP
> 30 ??
Posted
Updated 10-Jan-24 14:30pm
v2

You are free to replace the range based for loop with the standard for loop. See, for instance Container Classes - Iterating over Containers - index based in the QT documentation.
 
Share this answer
 
What you have coded is the C++ foreach which iterates a list.

Assuming I understand what you are asking ... if you want to do it by index then you can use the size() operator of the QList Class | Qt Core 6.6.1[^] to get the number of elements. something like:
C++
    for (int index = 0; index < list.size(); ++index)
    {
        qDebug() << list[index];
    }
// index will now be equal to list.size();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900