O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Anatomy of a QObject-derived class

The header file check_available_groceries.h, being a QObject-derived class, has the following default contents:

#ifndef CHECK_AVAILABLE_GROCERIES_H#define CHECK_AVAILABLE_GROCERIES_H#include <QObject>class CheckAvailableGroceries : public QObject{    Q_OBJECTpublic:    explicit CheckAvailableGroceries(QObject *parent = nullptr);signals:public slots:};#endif // CHECKAVAILABLEGROCERIES_H

Besides what is customary in a C++ class definition, you might notice a few novel, Qt-specific elements. This is what they are for:

  • #include <QObject>: Qt generally follows the rule of one class per file. So you can expect to be able to include a file corresponding to the class that you want to derive from. The Q prefix is common ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required