qt - 在 Qt 中获取运行时架构信息

标签 qt qt4

如果用户的系统是 Win 7-32 或 Win7-64,我如何在运行时发现使用 Qt?

最佳答案

没有办法只使用 Qt,AFAIK。以下是您的操作方法。

#include <windows.h>
#include <tchar.h>
#include <QtCore/QSysInfo>

typedef enum { Win_64, Win_32, Error, Other } OsType;

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

OsType checkOS() {
#ifndef Q_OS_WIN32
    return Other;
#else
    // An application compiled for 64 bits can only run on a 64 bit os,
    // so no need to check any further.
    if (QSysInfo::WordSize == 64) return Win7_64;
    // A 32 bit application may be running on a 64 bit OS.
    BOOL is64 = FALSE;
    // IsWow64Process may not be available in kernel32 on all Windows versions, so we bind to it
    // at runtime.
    LPFN_ISWOW64PROCESS fnIsWow64Process;
    fnIsWow64Process = (LPFN_ISWOW64PROCESS)
            GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
    // No way it's a 64 bit OS if it doesn't have this API.
    if (fnIsWow64Process == NULL) return Win_32;
    // Note that GetCurrentProcess() can't fail.
    if (!IsWow64Process(GetCurrentProcess(), &is64)) return Error; // The check has failed.
    return is64 ? Win_64 : Win_32;
#endif
}

关于qt - 在 Qt 中获取运行时架构信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11045163/

相关文章:

c++ - QT多项目配置

database - 在 Linux 中打开 MS Access 文件

c++ - 如何获取当前用户权限组?

python - Qt 设计器 : how to add custom slot and code to a button

qt - 当 QGraphicsScene 中宽度减小到 200 以下时,x,y 点会发生移动

html - 如何将突出显示的文本从 QSyntaxHighlighter 转换为 html 字符串?

c++ - Qt Creator 的替代编译器?

c++ - 在 QScrollarea 内绘制 QLabel

c++ - 连接 Qt 应用程序中的 GUI 和计算

c++ - 如何恢复 QMainWindow 的初始 centralwidget?