运行时获取的信息架构Qt中(Getting runtime architecture informa

2019-09-18 03:20发布

我怎么可能会发现,在运行时,使用Qt,如果用户的系统是赢7-32或Win7-64?

Answer 1:

没有完全使用Qt,据我所知这样做的方式。 下面是你如何做到这一点。

#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
}


Answer 2:

QT间期5的情况下,你可以使用QSysInfo像静态函数prettyProductName()currentCpuArchitecture()



文章来源: Getting runtime architecture information in Qt
标签: qt qt4