Search code examples
c++qtvisual-c++mfcqtnetwork

Win 32 API in Qt


I have a program written using MFC to communicate with a device over the Ethernet. I need to rewrite it and convert it to Qt.

The MFC program uses Win API functions like CreateFile, ReadFile (to get network packet) and DeviceIOControl (to talk to the protocol used to facilitate communication)

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?

Is there a standard mechanism for converting MFC code to Qt?


Solution

  • Can I use these functions - CreateFile, ReadFile and DeviceIOControl in my Qt code directly if I include Windows.h ?

    Yes.

    How about about Win API functions used for concurrency, like WaitForSingleObject and Mutex? What part of Win API is/is not available in Qt?

    You can use any part of the Win API.

    Is there a standard mechanism for converting MFC code to Qt?

    There is no standard mechanism. However, for the aforementioned functionality, you really want to look into the Qt alternatives, like QMutex, etc.

    Also, you would need to consider whether the conversion is worth it. After all, Qt will use the Windows API on Windows in the background.

    Assuming you wish to make your code cross-platform, you would really like to migrate away from the direct Windows API usage, otherwise your code will end up full of compilation-time preprocessor directives.