How to do it...

Let's get started by following these steps:

  1. Let's create a Qt Widgets Application project and open up mainwindow.cpp. After that, add the following headers to the top of the source code:
#include <QPushButton>#include <QGridLayout>#include <QMessageBox>#include <QTime>#include <QDebug>
  1. Create a QGridLayout object and set its parent as centralWidget:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){    ui->setupUi(this);    QGridLayout *layout = new QGridLayout(ui->centralWidget);
  1. Create a QTime object. We will be using this to measure the performance of our next operation:
QTime* time = new QTime;time->start();
  1. We will use two loops to fill in 600 push buttons to our grid layout and connect ...

Get Qt5 C++ GUI Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.