简体   繁体   English

将 Qt 集成到现有的 VS 项目中以替换 WinAPI

[英]Integrate Qt into existing VS project to replace WinAPI

I'm using VS2019 and Qt 5.12.9, and I have an old C++ project that currently uses WinAPI for its UI elements.我正在使用 VS2019 和 Qt 5.12.9,并且我有一个旧的 C++ 项目,该项目目前使用 WinAPI 作为其 UI 元素。 I would like to gradually replace this with UI implemented in Qt, at first targeting specific windows, and eventually phasing out WinAPI altogether.我想逐渐用 Qt 中实现的 UI 替换它,首先针对特定的 windows,最终完全淘汰 WinAPI。 To this end, I have two questions:为此,我有两个问题:

  1. How do I modify the VS project files so the project will perform all the necessary build operations (.moc files, etc.)?如何修改 VS 项目文件,以便项目执行所有必要的构建操作(.moc 文件等)?
  2. Is it possible to have Qt and WinAPI UI "side-by-side"?是否可以“并排”使用 Qt 和 WinAPI UI? In other words, the main window would still use the Windows message loop and window procedures, but for specific windows, I would instantiate Qt objects. In other words, the main window would still use the Windows message loop and window procedures, but for specific windows, I would instantiate Qt objects.

Please keep in mind that the setup described in 2) is a temporary solution.请记住,2) 中描述的设置是临时解决方案。 I don't intend to juggle the two forever, the project is just too large to completely replace the UI right away.我不打算永远兼顾这两者,这个项目太大了,无法立即完全替换 UI。

Thanks in advance!提前致谢!

So based on the recommendations of @IInspectable in the comments, I decided to try upgrading the app using WinUI instead of Qt.因此,根据评论中@IInspectable 的建议,我决定尝试使用 WinUI 而不是 Qt 升级应用程序。 The issues I ran into there will require their own separate question, so for now, I'll post my own conclusions here:我在那里遇到的问题需要他们自己单独的问题,所以现在,我将在这里发表我自己的结论:

  1. If you want to use Qt, the most reliable option is to start an entirely new VS project (and maybe port over some of your backend code).如果你想使用 Qt,最可靠的选择是启动一个全新的 VS 项目(也许移植一些后端代码)。 Mixing Qt with WinAPI is just too complicated and unreliable.将 Qt 与 WinAPI 混合太复杂且不可靠。
  2. If you want to use WinUI, keep in mind that your application will only run on Windows 10 .如果您想使用 WinUI,请记住您的应用程序只能在 Windows 10 上运行 If that isn't a concern, but you are working with legacy code, you may also need to untangle a lot of old configurations (Windows version defines, etc.) that are necessary for WinUI to work.如果这不是问题,但您使用的是遗留代码,您可能还需要解开 WinUI 工作所必需的许多旧配置(Windows 版本定义等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM