![](/img/trans.png)
[英]Qt automatically generated .rc file cannot open include file 'windows.h'
[英]Qt5.14 cannot find “windows.h” header?
我在 Linux Fedora fc31_x86_64 上使用 Qt5.14。 我正在閱讀 Guillaume Lazar 的書“Mastering Qt5”。
在第 2 章中,我嘗試使用書中的示例創建一個跨平台的桌面應用程序,該應用程序檢索已使用的內存量和 CPU 負載。 但是當我嘗試在我的項目中包含windows.h
時,編譯器會抱怨找不到這個文件?
那么如何在 linux 上的 Qt5 中包含“windows.h”?
這是書中的例子:
// 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;
}
這是我的錯,因為我在閱讀整個程序之前就匆匆忙忙地編譯了程序。 在練習結束時,他使用條件編譯,所以如果它在 windows 上,它使用<windows.h>
。
這本書應該在練習開始時提到這一點,或者告訴我們在練習結束之前不要編譯練習。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.