0

I'm looking at an example header file for Qt WebSockets and I'm a beginner with C++ and I'm trying to figure out what exactly the #define is doing.

I understand that #define acts to define a global variable but I'm unsure what this variable ECHOCLIENT_H is actually doing. It isn't in the subsequent main function or anywhere else. What is it's function?

#ifndef ECHOCLIENT_H
#define ECHOCLIENT_H

#include <QtCore/QObject>
#include <QtWebSockets/QWebSocket>

class EchoClient : public QObject
{
    Q_OBJECT
public:
    explicit EchoClient(const QUrl &url, bool debug = false, QObject *parent = nullptr);

Q_SIGNALS:
    void closed();

private Q_SLOTS:
    void onConnected();
    void onTextMessageReceived(QString message);

private:
    QWebSocket m_webSocket;
    QUrl m_url;
    bool m_debug;
};

#endif // ECHOCLIENT_H
IllyaKara
  • 109
  • 4
  • They are called header or inclusion guards. They ensure that even if the file is included more than once the part been the #ifndef and #endif will only be processed once. – siride Feb 16 '22 at 00:04

0 Answers0