I am using Qt5.14 on Linux Fedora fc31_x86_64. And I am reading Guillaume Lazar book "Mastering Qt5".
On the chapter 2 I am trying to use the example in the book to create a cross-platform desktop application that retrieves the amount of used memoery, and CPU load. But when I try to include windows.h
in my projects, the compiler complains that this file can't be found?
So how to include "windows.h" in Qt5 on linux?
This is the example from the book:
// In SysInfo.h
class SysInfo
{
public:
SysInfo();
virtual ~SysInfo();
virtual void init() = 0;
virtual double cpuLoadAverage() = 0;
virtual double memoryUsed() = 0;
};
// In SysInfo.cpp
#include "SysInfo.h"
SysInfo::SysInfo()
{
}
SysInfo::~SysInfo()
{
}
#include "SysInfoWindowsImpl.h"
#include <windows.h>
SysInfoWindowsImpl::SysInfoWindowsImpl() :
SysInfo()
{
}
double SysInfoWindowsImpl::memoryUsed()
{
MEMORYSTATUSEX memoryStatus;
memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memoryStatus);
qulonglong memoryPhysicalUsed =
memoryStatus.ullTotalPhys - memoryStatus.ullAvailPhys;
return (double)memoryPhysicalUsed /
(double)memoryStatus.ullTotalPhys * 100.0;
}
It was my bad because I've rushed myself to compile the program before reading the whole of it. In the end of the exercise he uses conditional compilation so if it is on windows it uses <windows.h>
.
The book should mention that at the beginning of the exercise or told that we don't compile the exercise right now until the end of the exercise.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.