gpt4 book ai didi

c++ - 获取操作系统是 32 位还是 64 位

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:34 24 4
gpt4 key购买 nike

从 Qt Framework 获取操作系统是 32 位还是 64 位的信息,以便在不同的操作系统上移植

无论应用程序是为 32 位还是 64 位构建的(QSysInfo::buildCpuArchitecture()),或者 CPU 是 32 位还是 64 位(QSysInfo::currentCpuArchitecture()),我都可以从 Qt 中获取信息,操作系统名称(QSysInfo::prettyProductName()) 但我还没有找到如何使用 Qt 确定操作系统是 32 位还是 64 位(应该是可移植的!)。Qt 中是否有任何函数可以获取该信息?

感谢您的宝贵时间。

qDebug() << "QSysInfo::buildCpuArchitecture():" << QSysInfo::buildCpuArchitecture();
qDebug() << "QSysInfo::currentCpuArchitecture():" << QSysInfo::currentCpuArchitecture();
qDebug() << "QSysInfo::buildAbi():" << QSysInfo::buildAbi();
qDebug() << "QSysInfo::prettyProductName():" << QSysInfo::prettyProductName();
// the result with MinGW 32-bit:
// QSysInfo::buildCpuArchitecture(): "i386"
// QSysInfo::currentCpuArchitecture(): "x86_64"
// QSysInfo::buildAbi(): "i386-little_endian-ilp32"
// QSysInfo::prettyProductName(): "Windows 10"
// the result with VC++ 64-bit:
// QSysInfo::buildCpuArchitecture(): "x86_64"
// QSysInfo::currentCpuArchitecture(): "x86_64"
// QSysInfo::buildAbi(): "x86_64-little_endian-llp64"
// QSysInfo::prettyProductName(): "Windows 10"

最佳答案

尽管顾名思义,currentCpuArchitecture 不会告诉您 CPU 是 32 位还是 64 位,但会告诉您操作系统的位数。

QString QSysInfo::currentCpuArchitecture()

Returns the architecture of the CPU that the application is running on, in text format. Note that this function depends on what the OS will report and may not detect the actual CPU architecture if the OS hides that information or is unable to provide it. For example, a 32-bit OS running on a 64-bit CPU is usually unable to determine the CPU is actually capable of running 64-bit programs.

http://doc.qt.io/qt-5/qsysinfo.html#currentCpuArchitecture

关于c++ - 获取操作系统是 32 位还是 64 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54379381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com