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

标签 c++ qt

从 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/

相关文章:

c++ - 中途反转/交换

qt - 如何根据QML中的文本增加矩形的高度

javascript - QML - 动态创建ListModel(JAVASCRIPT问题)

c++ - 在 C++ 中读取 txt 文件时跳过特定内容

c++ - 使用 cublas saxpy 时出错

c++ - 使用 Boost.Spirit 解析混合值和键值对

c++ - 是否可以强制父类(super class)中的非 const 虚方法优先于子类中同名的 const 方法?

c++ - 尝试使用 visual studio 2008 在 Windows 中编译 qt-labs-qt3d 时出现错误

c++ - 如何在 Qt 应用程序中使用样式表更改 QPushButton 图标

c++ - Qt永久线程