wxWidgets: Changes Since wxWidgets 2.8 (original) (raw)

This topic describes backwards-incompatible changes in wxWidgets 3.0 compared to the last stable release and is very important to read if you are updating from the 2.8 or an older version.

And even if you hadn't used any previous version of wxWidgets and are starting directly with 3.0, it can still be useful to have at least a quick look at it just to know that some of the older examples and tutorials may not be applicable any more to wxWidgets 3.0.

The incompatible changes can be grouped into the following categories:


If you used Unicode build of wxWidgets 2.8 or previous version, please read Unicode Support in wxWidgets for the details about how the API changed in 3.0 as a lot of the information which was correct before doesn't apply any longer.

For example, the notorious (due to the confusion they created) macros [wxT()](group%5F%5Fgroup%5F%5Ffuncmacro%5F%5Fstring.html#ga437ea6ba615b75dac8603e96ec864160 "This macro can be used with character and string literals (in other words, 'x' or "foo") to automatic...") and [_T()](group%5F%5Fgroup%5F%5Ffuncmacro%5F%5Fstring.html#ga7dfc2888539861afe6c4337ef315472b "This macro is exactly the same as wxT() and is defined in wxWidgets simply because it may be more int...") are not needed at all any longer. Basically, you can remove them from any code which used them. On the other hand, there is no particular harm in leaving them neither as the code will still compile and work correctly – you only need to remove them if you think that your code looks tidier without them. You also don't need to use wxChar any longer but can directly use the standard wchar_t type even if, again, wxChar continues to work.

The most serious backwards-incompatible change is related to the change of return type of wxString::c_str() method: it returns a special proxy object instead of a simple char* or wchar_t* now. Because of this, you cannot pass its result to any standard vararg functions such as printf() any more as described in Unicode-Related Compilation Errors. All wxWidgets functions, such as wxPrintf(), wxLogMessage() &c still work with it, but passing it to printf() will now result in a crash. It is strongly advised to recompile your code with a compiler warning about passing non-POD objects to vararg functions, such as g++.

The change of the type of wxString::c_str() can also result in compilation errors when passing its result to a function overloaded to take both narrow and wide strings and in this case you must select the version which you really want to use, e.g.:

void OpenLogFile(const char *filename);

void OpenLogFile(const wchar_t *filename);

OpenLogFile(s);

OpenLogFile(s.c_str());

OpenLogFile(s.wx_str());

OpenLogFile(s.mb_str());

OpenLogFile(s.wc_str());

A common example of such problem arises with std::fstream class constructor in Microsoft Visual C++ standard library implementation. In addition to a constructor from const char * which this class must have, it also provides a constructor taking a wide character file name. Because of this, code like the following

#include

void MyFunc(const wxString& filename)

{

std::ifstream ifs(filename.c_str());

...

}

does not compile when using Microsoft Visual C++ and needs to be changed to use mb_str() (which will not work for file names containing Unicode characters, consider using wxWidgets classes and functions to work with such file names as they are not supported by standard C++ library).

The other class of incompatible changes is due to modifying some virtual methods to use [wxString](classwx%5Fstring.html "String class for passing textual data to or receiving it from wxWidgets.") parameters instead of const wxChar* ones to make them accept both narrow and wide strings. This is not a problem if you simply call these functions but you need to change the signature of the derived class versions if you override them as otherwise they wouldn't be called any more. Again, the best way to ensure that this problem doesn't arise is to rebuild your code using a compiler which warns about function signature mismatch (you can use -Woverloaded-virtual g++ option).

Finally, a few structure fields, notable [wxCmdLineEntryDesc::shortName](structwx%5Fcmd%5Fline%5Fentry%5Fdesc.html#a1fa5b1fb90ff3051a011a6ce10261796 "The usual, short, name of the switch or the option."), longName and description fields have been changed to be of type const char* instead of const wxChar* so you will need to remove [wxT()](group%5F%5Fgroup%5F%5Ffuncmacro%5F%5Fstring.html#ga437ea6ba615b75dac8603e96ec864160 "This macro can be used with character and string literals (in other words, 'x' or "foo") to automatic...") or [_T()](group%5F%5Fgroup%5F%5Ffuncmacro%5F%5Fstring.html#ga7dfc2888539861afe6c4337ef315472b "This macro is exactly the same as wxT() and is defined in wxWidgets simply because it may be more int...") if you used it with their initializers.

Miscellaneous Other Changes