Nominate our 2022 Qt Champions!

Can i use windows API in Qt?

  • If yes, does it will work in all platform which Qt support or only windows?

  • Yes, you can mix Windows API code and Qt code.
    No, it is not portable as the Windows API is naturally bound to the Windows platform. It might run on emulated environments (Wine, Crossover).

  • It means it will not work on MAC and Linux. I have seen a function @QWidget::winId () const@.
    In documentation i have read about this function but i am not clear about its platform dependency. can you make it more clear?

  • Qt is built on top of native system APIs (Windows SDK, Carbon, Cacao, ...). Each of these APIs use their own types of identifiers (HWND, HIViewRef, NSView, ...), whereas Qt provides a platform-independent identifier (QWidget*).

    If you now want to use platform-specific API you will have to use a platform-specific identifier - this it what QWidget::winId() does. It returns a platform-specific identifier (HWND on Windows, HIViewRef or NSView on Mac OS X, ...).

    As long as you pass this platform-specific identifier to platform-independent functions like QWidget::find() your application will remain portable. As soon as you pass it to a platform-specific function, for example GetWindowText(), your application is no longer platform-independent as the GetWindowText() function is part of the Windows SDK which is only available on Windows (but not on Mac OS X, ...).

Log in to reply