简体   繁体   English

Qt5.14 找不到“windows.h” header?

[英]Qt5.14 cannot find “windows.h” header?

I am using Qt5.14 on Linux Fedora fc31_x86_64.我在 Linux Fedora fc31_x86_64 上使用 Qt5.14。 And I am reading Guillaume Lazar book "Mastering Qt5".我正在阅读 Guillaume Lazar 的书“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.在第 2 章中,我尝试使用书中的示例创建一个跨平台的桌面应用程序,该应用程序检索已使用的内存量和 CPU 负载。 But when I try to include windows.h in my projects, the compiler complains that this file can't be found?但是当我尝试在我的项目中包含windows.h时,编译器会抱怨找不到这个文件?

So how to include "windows.h" in Qt5 on linux?那么如何在 linux 上的 Qt5 中包含“windows.h”?

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> .在练习结束时,他使用条件编译,所以如果它在 windows 上,它使用<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.这本书应该在练习开始时提到这一点,或者告诉我们在练习结束之前不要编译练习。

  • As @MM said If I comment out parts related to Mac-Os and Windows it works for me on Linux.正如@MM 所说,如果我注释掉与 Mac-Os 和 Windows 相关的部分,它在 Linux 上对我有用。 But the whole program is a cross-platform which uses conditional compilation to detect the OS on which Qt is running in the pre-compilation step.但是整个程序是跨平台的,它在预编译步骤中使用条件编译来检测 Qt 运行的操作系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM