C++ wxWidgets Example

Interested in creating simple C++ GUIs under Linux? wxWidgets is straightforward and efficient. The following is an example of basic use. My favourite free GUI designer is wxFormBuilder. You can get started with wxFormBuilder by following the steps below (tested on Ubuntu 12.04LTS):

sudo apt-get install wxformbuilder

To get wxWidgets for Linux:

sudo apt-get install wx2.8-headers libwxgtk2.8-0 libwxgtk2.8-dev

You might also need to install some other dependencies using apt-get or the Ubuntu software package manager.

The following sites explain in more detail:

http://wiki.wxwidgets.org/Installing_and_configuring_under_Ubuntu
http://wiki.wxwidgets.org/Compiling_and_getting_started

After designing your GUI, wxFormBuilder will generate a .fbp file. You need to set it to generate C++. It will produce noname.cpp & noname.h, which need to be edited to produce a fully working GUI. The example source below demonstrates what changes need to be made to the wxFormBuilder generated files. To compile it, use the following command:

g++ my_wx_gui.cpp `wx-config –cppflags` `wx-config –libs`

You may also need to set symbolic links pointing to the include files. See above links for detailed instructions.

my_wx_gui.cpp

my_wx_gui.hpp

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.