QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(label1); layout->addWidget(label2); layout->addWidget(label3); int itemCount = layout->count(); // itemCount = 3
QVBoxLayout *layout = new QVBoxLayout; for (int i = 0; i < 5; i++) { QLabel *label = new QLabel(QString::number(i)); layout->addWidget(label); } int itemCount = layout->count(); // itemCount = 5This example dynamically creates five QLabel widgets using a for loop and adds them to the QVBoxLayout. The count() function is then used to determine the number of items in the layout. The QVBoxLayout and count() function are part of the Qt library, which is a cross-platform application development framework.