Separate wxString class

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tigerbeard
Earned some good credits
Earned some good credits
Posts: 123
Joined: Sat Oct 07, 2006 1:56 pm

Separate wxString class

Post by tigerbeard »

I thought I had read about this in the forum before, but I just can't find it.


I would love to be able to use wxString in a some of my base classes I use for all projects, including non-GUI projects or those that can't have a wxWidgets libary dependency for some reason. Today I typedef wxString it to std::string and do not use many of the advanced functions in those base classes, e.g. Format() (not using C++20).

I had a look at the sources for wxString. Its quite entangled with so many other include files of the wxWidgets build that its surely not easy to single out that class to a set of stand-alone header and cpp files. Maybe its possible to shrink down the number of dependencies when external requirements are cut down, e.g. not supporting WinCE or ceratin OS/compilers etc. Biggest challenge probably is the really impressive Macro Magic used for the vararg functions.

Does anything like that exist already? Or did someone try that before and shared lessons learned?
System config: Xubuntu22.04, wxWidgets 3.0.5,gcc, C::B
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Separate wxString class

Post by PB »

FWIW, even wxWidgets maintainers strongly recommend avoiding wxString unless required. From the official docs:
While the use of wxString is unavoidable in wxWidgets programs, you are encouraged to use the standard string classes std::string or std::wstring in your applications and convert them to and from wxString only when interacting with wxWidgets.
wxString and others (e.g., MFC's CString or Qt's QString) are relics of the past, when standard string class was not (widely) available.

I do agree that wxString has few rather handy methods not easily available otherwise, but I don't think it's worth doing changes in wxWidgets source.

If you link just to wxBase, I don't think many dependencies are pulled in, particularly when linking statically.

BTW, there is no Windows CE support in wxWidgets, even its vestiges were removed long time ago.
tigerbeard
Earned some good credits
Earned some good credits
Posts: 123
Joined: Sat Oct 07, 2006 1:56 pm

Re: Separate wxString class

Post by tigerbeard »

PB wrote: Sat Feb 04, 2023 2:28 pm BTW, there is no Windows CE support in wxWidgets, even its vestiges were removed long time ago.
No idea if still supported, just came across leftovers in 3.05. sources. But I know from experience how hard it is to really clean out all traces of old stuff. :D
System config: Xubuntu22.04, wxWidgets 3.0.5,gcc, C::B
Post Reply