QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(button1); layout->addWidget(button2); int numItems = layout->count(); qDebug() << "Number of items in layout: " << numItems;
QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(label1); layout->addWidget(label2); layout->addWidget(label3); int numItems = layout->count(); qDebug() << "Number of items in layout: " << numItems;In this example, we create a QHBoxLayout and add three labels to it. We then use the count method to return the number of items in the layout and print it to the console. Package Library: Qt Core Library.