October 3, 2011

pratik041 pratik041
Lab Rat
346 posts

Can i use windows API in Qt?

 

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

 Signature 

Pratik Agrawal

3 replies

October 3, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

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).

October 3, 2011

pratik041 pratik041
Lab Rat
346 posts

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?

 Signature 

Pratik Agrawal

October 3, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

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, …).

 
  ‹‹ problems with Qt and strange caracters!      unix command slot creation ››

You must log in to post a reply. Not a member yet? Register here!