Starting GUI

Hi,
Ive been using C++ for a while now, but i never started using GUI with it. Ive looked around, and from what i can tell, making GUI programs is different depending on operating system, im using linux at the moment. But i the thing im confused about are all the different APIs. To start what is an API, and which is the best to use?
API = Application Programming Interface

For cross platform Gui programming, I would look here : http://qt.nokia.com/products/

To clarify Windows has its own built in library(vague term) for accessing UI elements - plus you can use others such as the cross platform alternatives as jloundy talks about.

Linux uses widgets. It does not have a base library therefore you have to pick one. Alternatively you can write your own of course.

API, Application Programming Interface, is more of a windows thing than linux.
The way I see an API is a direct way to tap in to the interface. Libraries kind of include everything in to your source code, API is a direct call to the the actual function of the application, mostly using dll calls. C++ encapsulates all of this for you so you don't need to worry about the API stuff.



There is some debate about which cross-platform toolkit is the best. The answer really depends how you want to use it, the licensing model you need, etc.

The three main, general purpose toolkits for C++ are Qt, which jloundry has already mentioned, along with wxWidgets and FLTK.

http://en.wikipedia.org/wiki/FLTK
http://www.fltk.org/

http://en.wikipedia.org/wiki/WxWidgets
http://wxwidgets.org

http://qt.nokia.com/
http://en.wikipedia.org/wiki/Qt_Development_Frameworks

(the Wikipedia pages for each toolkit include lists of project which are using it).

Qt is the most mature and complete, providing asbsractions of system functionality as well as GUI functionality. But it also the most complex to use (it requires the use of a meta-compiler), the heaviest, and has the most restricitve licence of the three. (And I believe it's the most common of the three in the commercial development world?)

wxWidgets I know the least about, but believe it has a reasonable following. Like Qt it is pretty complete and heavy. It is also of particular interest to people coming to cross-platform development from the Windows world as its structure is simalar to that of MFC.

FLTK is, in contrast, a much lighter weight toolkit. But it provides a lot less (almost no) non-GUI functionality than the other two, and it rather less elegant. But its simplicity and lightness is what makes it attractive to projects which require minimal GUI functionality and therefore do not want to take the hit of either Qt or wxWidgets. For example, an application that just requires a main window to host OpenGL or CAIRO.

In case it is of any relevance, Stroustrup chose FLTK to use as the GUI widget toolkit in his book "Programming -- Principles and Practice Using C++". So if you want to learn GUI programing from Stroustrup it might be the way to go, at least to start with. (While each GUI toolkit have their own idioms and quirks, the general principles are transferable.)

Andy

P.S. Googling for Qt vx wxWidges vs FLTK turns up loads of debates, including:

wxWidgets vs Qt
http://stackoverflow.com/questions/2886258/wxwidgets-vs-qt

FLTK Vs GTK Vs Wxwidgets Vs Qt
http://www.gidforums.com/t-8113.html

Qt or wxWidgets?
http://discuss.joelonsoftware.com/default.asp?joel.3.726287.12
Last edited on
Ok, So are the toolkits that you were talking about (Qt, FLTK, and wxWidget) all different compilers? Will i need to have a new compiler to work with GUI? I worked with java for a little bit and was able to use the same compiler for both nonGUI and GUI. Will i still be programming with C++, because on the Qt website it talks about "learning Qt".
Thanks
Joel
are the toolkits that you were talking about (Qt, FLTK, and wxWidget) all different compilers?


No, Qt, FLTK, and wxWidget are all different GUI toolkits (or GUI frameworks)

In all three cases, they are class based, as is the Microsoft specific MFC.

From C++ you can also use C-APIs, like GTK+ and the GUI parts of WIN32 (the latter is Windows specific, and while there is a WIN32 port of the former, I have not seen much evidence of its use, esp. cf. Qt, FLTK, and wxWidget)

Will i need to have a new compiler to work with GUI?


No. I believe that all three work with all compliant compilers.

I have all three tookits on my Windows machine working with both gcc and vc++, and on a Ubuntu machine using gcc. And as an IDE I'm using both Visual Studio (Windows only) and CodeLite.

(Both IDEs -- and others like Code::Blocks -- know how to handle Qt projects, when the Qt toolkit, etc. is installed. See below re Qt moc)

Will i still be programming with C++, because on the Qt website it talks about "learning Qt".


Qt is C++ based.

But when you build a Qt project you have an extra build step, which uses their "meta object compiler" (moc). This generates extra C++ code from .moc files. You then compile and link bother this generated C++ and your own.

(I'm only a beginner when it comes to Qt. So I am still learning my way round moc, etc. There is also qmake and .ui files to worry about, and other things.)

But all the libraries have their way of doing things, so you would also be expected to "Learn wxWidgets", "Learn FLTK", ... !

The first thing I do when investigating a new toolkit, code library, or SDK is check out the sample code. All the above toolkits provide a number of basic samples, plus code for some more involved apps.

Andy

P.S. One of the FLTK designers provides various additional examples on his "Cheat Page", if you want to get a feel of what it's capable of: http://seriss.com/people/erco/fltk/

The information I've posted is from notes of my own recent investigation. I coded a small app in WTL (which I knew already) Qt, wxWidgets, and FLTK and then compared the code.

In the end I chose to go with FLTK as the app I am working on is small and has few additional requirements outside of the GUI and some standard C++ algorithmic code. FLTK isn't as pretty as the others, but it is the simplest for a basic little app.

Qt (and wxWidgets) are good if you have code that uses a lot of non-GUI system functionality, which would involve a lot of #ifdef-ing (or similar) if Qt hadn't abstracted things for you.
Last edited on
Ok, so ive downloaded the Qt Creator from the website, but how does this help me make GUI in Geany (the compiler im using)? will i have to code it in the Qt creator, or how does it work? I see all the options for making projects and what not and the creator seems to be a different compiler all together...
I don't know about Qt Creator itself. When I installed Qt it integrated itself with Visual Studio. I think CodeLite was Qt capable already.

But I don't think there is a QT plug-in for Geany. It's still on their wish list.
http://www.geany.org/Support/PluginWishlist

So if you want to use the same IDE for both Qt and other work, you might want to have a look at Code::Blocks and CodeLite. (I use the latter, but have seen Code::Blocks mentioned on this site quite a bit.)

There are very prob others, but these are the one I see mentioned the most. There is a list of IDEs on Wikipedia.org [1], but I don't know which ones support Qt. But I do know that there is a Qt plug-in for Eclipse CDT.

Andy

[1] http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments
Last edited on
Topic archived. No new replies allowed.