Qt如何在一个进程中兼容多个qt版本

qq_26440283 qq_26440283 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

// since multiple Qt versions can be used in one process

// each one has to have window class names with a unique name

// The first instance gets the unmodified name; if the class

// has already been registered by another instance of Qt then // add a UUID. The check needs to be performed for each name

// in case new message windows are added (QTBUG-81347).

qwindowscontext的registerWindowClass的注释明确表示可以在一个进程中使用多个版本的qt,但是实际上并非如此,在源码中有一个用于判断窗口类是否被注册的代码并没有生效:

const auto appInstance = static_cast<HINSTANCE>(GetModuleHandle(nullptr));
WNDCLASS wcinfo;

const bool classExists = GetClassInfo(appInstance, reinterpret_cast<LPCWSTR>(cname.utf16()), &wcinfo) == TRUE && wcinfo.lpfnWndProc != proc;

if (classExists)

    cname += QUuid::createUuid().toString();

导致窗口类重名并没有正确判断出,导致窗口类名重复注册(但是第二个注册的时候失败了)。最终导致的结果就是后续使用的qt版本开发的qt界面打开后白屏,无法正常显示。该如何解决这个问题呢。

...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
qq_26440283
Qt 21,503 成员 26,693 内容