FAQ

From WxWiki

Jump to: navigation, search

This is a user maintained FAQ, the purpose of which is to allow easy augmentation of questions and answers to build up a large knowledge base on wxWidgets. If you don't find your question or the answer to your question doesn't give enough details, check the Official wxWidgets FAQ as well as the FAQs maintained on the wxWidgets Forums (don't miss the exhaustive C++ Users Forum FAQ or Paul's wxWidgets Newbie FAQ).

Contents

[edit] Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

This is the default background colour for frames on Microsoft Windows. You can get the familiar light-grey background by putting a wxPanel on the frame first, and putting all your other controls on this wxPanel. If the wxPanel is the only child window of the frame then it will automatically take up the entire client area of the frame.

wxPanel Example
wxBoxSizer* topSizer = new wxBoxSizer( wxEXPAND );
wxPanel *panel = new wxPanel(this, wxID_ANY, 
                             wxDefaultPosition, 
                             wxDefaultSize,
                             wxTAB_TRAVERSAL,
                             _("mypanel"));
panel->SetSizer(topSizer);
wxButton *ok_button = new wxButton( panel, wxID_OK );
wxButton *cancel_button = new wxButton( panel, wxID_CANCEL );
topSizer->Add(ok_button);
topSizer->Add(cancel_button);

See wxPanel in the documentation for more information on panels.

[edit] XPM images don't display the 'silver' colour correctly

In wxWidgets XPM, "silver" is not defined as a color. This "silver" will be generated by a lot of external tools that output XPM. You will need to replace it manually in the XPM file with the hex number C6C6C6.

[edit] Why do I get the linker error "undefined reference to `MyFrame virtual table'"?

Probably you do DECLARE_EVENT_TABLE() for MyFrame, but you don't create an event table.

This can actually happen in any case where virtual methods are declared but not defined. This can sometimes happen in roundabout ways, e.g., if you are inheriting from a class with a virtual destructor, but you haven't defined a virtual destructor for your class. You can find more information about this in the GCC FAQ.

One last possible cause is a mismatch between #pragma interface and #pragma implementation. If you don't know what these are, they're probably not the problem.

[edit] Under Linux, upon running my application, why do I get the error message "error while loading shared libraries: libwx_gtk-x.x.so"?

This message means that the library is not in the system search path for shared libraries. Usually this means either:

  • You forgot to run ldconfig after running make install to install wxWidgets (using Linux).

On some linux running ldconfig isn't enought because you have to add this line to your /etc/ld.so.conf file:

/usr/local/lib

Once it's added, run ldconfig as root.

  • make install installed the shared library in a directory (usually /usr/local/lib) not scanned by ldconfig on your system.

To resolve this issue, you can set the LD_LIBRARY_PATH environment variable to include the directory containing the shared library. Alternatively, add this directory to your /etc/ld.so.conf file, and re-run ldconfig.

A related question :

./wxbasic: error while loading shared libraries:
../../lib/libwx_gtk-2.3.so.0.0.0: cannot open shared object file:
No such directory

This is a classic problem and I have to say that for once, it's simpler on Windows.

Whereas Windows has a single PATH with both .exe and .dll, Unix is different. Usually the executable is on PATH and shared libraries are on LD_LIBRARY_PATH or something like that. I think that answers part of your question about how things are organized, but alas it's not relevant to this problem.

This particular user is having problems, I think, because of the way you linked wxBasic. I bet you linked

../../lib/libwx_gtk-2.3.so.0.0.0

into your executable and not something like

-L../../lib -lwx_gtk-2.3

When you used that relative path (or even a full path), the path to the shared library is copied into the executable. When the executable is run, it expects to find the shared library in ../../lib, not in one of the "standard places" like /usr/lib.

So what we usually do is use the -L and -l options to the C++ compiler/linker. The -L says WHERE to look for libraries and the -l suggests what the library is called. I say "suggests" because the libabc.so (or libabc.a) is refered to with -labc. Also, the version number stuff at the end is somehow ignored with the -l in a way I don't understand.

[edit] Why does my control take up the whole frame even though I give it an explicit size?

If you only have one window in a frame, that window will automatically take the whole space. If you really want only one window that doesn't take the whole space, try adding a second, blank wxWindow to the frame.

Under normal circumstances, however, the only child of your frame should be a wxPanel, and any other controls should be descendents of that panel. Having a panel present in this manner can solve a number of unexpected behaviors including incorrect colors, missing events, and improper sizer behavior.

[edit] Why does my application crash on exit?

Chances are you are freeing something that was already freed (see Avoiding Memory Leaks).

If you are using SuSE 8.2, you are using a buggy non-release version of gcc, which causes the crashing. SuSE 10.2 also had some wrongly-configured WxWidgets rpm packages available from Packman-Bremen that crashed on exit.

[edit] Why isn't wxString( wxT("(non iso8859-1 chars)") ) displayed correctly and why can't it be converted back to the initial encoding?

Because the input charset of a cpp compiler is 7bit-ascii. Chars >0x7f are considered iso8859-1. It is these iso8859-1 chars that are encoded to unicode and not the ones of your native language. Do not use wchar_t string literals. Use wxString( "(non iso8859-1 chars)", wxConvLibc ) instead.

[edit] Why won't my Mac application take focus?

You need to set up the resources to operate in the Mac windowing environment by creating a bundle. For details, see WxMac_Issues.

If you're using python, newer versions have the resources set up correctly by default. However, in older versions you will need to use pythonw as the interpreter instead of python.

[edit] What's the difference between a wxFrame and a wxWindow?

A wxFrame is a top-level window, normally referred to as windows in interfaces. A wxWindow is a generic class for any drawable object on the screen. Under normal circumstances, you create a frame, place a panel in the frame, then place other wxWindow subclasses (wxButton, wxTextCtrl, etc.) in the panel.

Personal tools