Adding the Mac OS implementation

Let's take a look at the Mac implementation of the SysInfo class. Start by creating a new C++ class named SysInfoMacImpl that inherits from the SysInfo class. Override SysInfo virtual functions and you should have a SysInfoMacImpl.h file like this:

#include "SysInfo.h" 
 
#include <QtGlobal> 
#include <QVector> 
 
class SysInfoMacImpl : public SysInfo 
{ 
public: 
    SysInfoMacImpl(); 
 
    void init() override; 
    double cpuLoadAverage() override; 
    double memoryUsed() override; 
}; 

The first implementation we will do will be the memoryUsed() function, in the SysInfoMacImpl.cpp file:

#include <mach/vm_statistics.h> #include <mach/mach_types.h> #include <mach/mach_init.h> #include <mach/mach_host.h> #include <mach/vm_map.h> SysInfoMacImpl::SysInfoMacImpl() ...

Get End to End GUI Development with Qt5 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.