wxWidget: Displaying results

My Program is a simple function calculator. The user is asked to provide two inputs. The program is to run the inputs through a function and spit out the answer as a float type. My problem lies with trying to display the results at the bottom of my frame/window. I tried using wxStaticText but the problem was that a variable could not be the value, or text displayed. Any tips, suggestion, and/or solutions. Thank you for your time :)
Do you want to convert from float to wxT? Altho my wxWidgets knowledge is limited, you could try this:

The wxWidget way is:

wxString stringnumber = wxString::Format(wxT("%d"), (int)number_to_convert);

Convert int to string

If you do use std::to_string (which requires a patch for MinGW, last I heard?) you need to do a bit more work to convert the resultant std::string to a wxString:

The wxT macro is provided to convert string literals to wxStrings. It is just the wxWidgets version of the Visual Studio _T() macro.

wxWidgets docs / String functions / wxT

To convert a std::string to a wxString you need to use a wxString constructor:

From from wxWidgets 2.9

std::string stlstring = "Hello world";
// assuming your string is encoded as the current locale encoding (wxConvLibc)
wxString mystring(stlstring);

With earlier versions of wxWidgets

std::string stlstring = "Hello world";
// assuming your string is encoded as UTF-8, change the wxConv* parameter as needed
wxString mystring(stlstring.c_str(), wxConvUTF8);

Converting everything to and from wxString


Also see:
wxString Class Reference / Converting to and from wxString
Last edited on
Guys I appreciate the responses, but my problem lies in displaying the results in a wxFrame. The idea is that the float value, upon being calculated, would be displayed, using a static text, in a result section on the bottom of the frame. I tried to use the float as the value of the wxStaticText but the compiler does not recognize or will not accept the float as the text for the static text element. In order to figure out the parameters of the static text element, I created a blank wxString and assigned some text to it. When substituted for the wxT it once again failed to compile.

wxStaticText *fr = new wxStaticText(panel, -1, wxT("f"), wxPoint(90,200)); // "f" is the value printed on the bottom of the screen

I want to substitute "f" with a float value.

wxStaticText *fr = new wxStaticText(panel, -1, some float variable, wxPoint(90,200)); // the goal is to print the numerical value of the variable

Any ideas?
wxStaticText's ctor takes a wxString. If you have a wxString object you can make it print whatever you want:

wxString whatever = "whatever";

wxStaticText *fr = new wxStaticText(panel, -1, whatever, wxPoint(90,200));

If you want to print a float, you need to first convert that float to a wxString, as andywestken has explained.
Last edited on
Thank you, i understood andywestken the first time, and I did convert to a wxstring. i just did not know that you have to use:

wxStaticText *fr = new wxStaticText(panel, -1, whatever, wxPoint(90,200));

I was really confused as to how you needed to setup the parameters for the wxStatictext element, I thought it was:

wxStaticText *fr = new wxStaticText(panel, -1, wxT(whatever), wxPoint(90,200));

Thank you gentlemen, really appreciate it.
Topic archived. No new replies allowed.