我有一个使用 MFC 编写的程序,用于通过以太网与设备通信。我需要重写它并将其转换为 Qt。
MFC 程序使用 Win API 函数,如 CreateFile、ReadFile(获取网络数据包)和 DeviceIOControl(与用于促进通信的协议(protocol)对话)
如果我包含 Windows.h,我可以直接在我的 Qt 代码中使用这些函数 - CreateFile、ReadFile 和 DeviceIOControl 吗?
WaitForSingleObject 和 Mutex 等用于并发的 Win API 函数怎么样? Win API 的哪一部分在 Qt 中不可用?
是否有将 MFC 代码转换为 Qt 的标准机制?
最佳答案
Can I use these functions - CreateFile, ReadFile and DeviceIOControl in my Qt code directly if I include Windows.h ?
是的。
How about about Win API functions used for concurrency, like WaitForSingleObject and Mutex? What part of Win API is/is not available in Qt?
您可以使用 Win API 的任何部分。
Is there a standard mechanism for converting MFC code to Qt?
没有标准机制。但是,对于上述功能,您确实需要研究 Qt 的替代方案,例如 QMutex 等。
此外,您还需要考虑转换是否值得。毕竟Qt会在后台使用Windows上的Windows API。
假设您希望让您的代码跨平台,您确实希望从直接使用 Windows API 迁移出来,否则您的代码最终将充满编译时预处理器指令。
关于c++ - Qt 中的 Win32 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23304590/