3

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

4

2 回答 2

2

没有办法专门使用 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
}
于 2012-06-15T14:28:52.773 回答
0

对于 Qt 5,您可以使用QSysInfo静态函数,例如prettyProductName()currentCpuArchitecture()

于 2018-09-24T12:55:55.740 回答