开发者

platform independent GUI

I want to make GUI for my application. It should work on multiple platforms. I wan开发者_运维技巧t most of the code to be portable for all the OS (unix, windows, MAC).

GTK and GLib looks as a good solution. I want to use native APIs too

How to do this all??


Qt may be good for that.


I like WxWidgets, really easy to use. It has bindings for multiple languages and you can mix it's C++ implementation with Win32 API (C code) easily.

http://www.wxwidgets.org/

A more lightweight alternative is FLTK

http://www.fltk.org/index.php


You will have to implement a PAL(Platform abstraction layer).
This layer should provide a abstraction over the actual platform calls by providing interfaces which are not platform dependednt. Once you move on to another platform, only the PAL needs to be implemented for that particular platform and the rest of the application can be used as is.


Qt seems like an option. But if you want to use Windows API's, it will not be portable. Qt in Windows will use stuff like CreateWindow etc. but you will not. E.g. the disassembler IDA was recently rewritten in Qt and is now cross-platform.


I Think its worthwhile learning the native windowing layer on each platform you are targetting.

As such:

  • Cocoa
    Cocoa is the native Mac OS X windowing layer. Its an Objective-C api, but its not hard to learn, and its easy to interop with either C or C++.
  • Win32 API
    The Windows API is a C API that implements the windows native widget set.
  • GTK+
    The Unix/Linux world is more complicated as its possible to have apps written against completely different widget set implementations. You need to choose the widget set used by your target environments default desktop: If you are targeting Ubuntu then GTK+ (2) is the API to target to access the Unity desktops "native" widget set.

I don't personally like QT as they've invented their own meta compiler, making QT code (ironically) hard to port to non QT environments. QT does however present an abstraction of the native Widget set where possible.

wxWidgets is a convenient wrapper API to use as it already wraps the Win32Api, Cocoa api and GTK+ on the relevant platforms. I avoided using it however as Wx is based on Microsoft MFC - a somewhat dated Document/View C++ framework and I wanted to understand the underlying platforms.


  • Edited with some corrections wrt QT.


Please take a look at Qt Framework. This will help you create cross platform GUI Applications. You would have to rely on API Offered by Qt for Native platform tasks, other wise if you proceed to use the native API's your code will not be portable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜