wxTextValidator



  • Hi,
    ich habe ein Problem mit einem wxTextCtrl Feld und dem zugehörigen Validator.
    Ich habe das Gefühl das gar kein Text aus dem Feld in die Variable die im Validator angegeben wurde geschrieben wird. Ausserdem stürzt das Programm immer beim Test mit einem std::string ab.

    Ich habe mal das MinimalSample modifiziert, damit ihr das nachvollziehen könnt.

    // ============================================================================
    // declarations
    // ============================================================================
    
    // ----------------------------------------------------------------------------
    // headers
    // ----------------------------------------------------------------------------
    
    // For compilers that support precompilation, includes "wx/wx.h".
    #include "wx/wxprec.h"
    
    #ifdef __BORLANDC__
        #pragma hdrstop
    #endif
    
    // for all others, include the necessary headers (this file is usually all you
    // need because it includes almost all "standard" wxWindows headers)
    #ifndef WX_PRECOMP
        #include "wx/wx.h"
    #endif
    
    // ----------------------------------------------------------------------------
    // resources
    // ----------------------------------------------------------------------------
    
    // the application icon (under Windows and OS/2 it is in resources)
    #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
        #include "mondrian.xpm"
    #endif
    
    #include <string>
    using namespace std;
    
    // ----------------------------------------------------------------------------
    // private classes
    // ----------------------------------------------------------------------------
    
    // Define a new application type, each program should derive a class from wxApp
    class MyApp : public wxApp
    {
    public:
        // override base class virtuals
        // ----------------------------
    
        // this one is called on application startup and is a good place for the app
        // initialization (doing it here and not in the ctor allows to have an error
        // return: if OnInit() returns false, the application terminates)
        virtual bool OnInit();
    
        // Die Methode die testet ob der inhalt des wxStrings dem vom std::string entspricht
        void TestVoc()
        {
            if(TestValue.compare( stdString.c_str() ) == 0){
                wxMessageBox("equal");
            }
        }
        MyApp():stdString("Hello"){}
    private:
        string stdString; // der std::string
        wxTextCtrl *TestInputField;// Das Textfeld
        wxString TestValue;// Hier sollte der Inhalt des Textfeldes gespeichert werden.
    
    };
    
    // Define a new frame type: this is going to be our main frame
    class MyFrame : public wxFrame
    {
    public:
        // ctor(s)
        MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
                long style = wxDEFAULT_FRAME_STYLE);
    private:
        // any class wishing to process wxWindows events must use this macro
        DECLARE_EVENT_TABLE()
    };
    
    // ----------------------------------------------------------------------------
    // constants
    // ----------------------------------------------------------------------------
    
    // IDs for the controls and the menu commands
    enum{
        // ID des Eingabefeldes:
        TestInputFieldID
    };
    
    // ----------------------------------------------------------------------------
    // event tables and other macros for wxWindows
    // ----------------------------------------------------------------------------
    
    // the event tables connect the wxWindows events with the functions (event
    // handlers) which process them. It can be also done at run-time, but for the
    // simple menu events like this the static method is much simpler.
    BEGIN_EVENT_TABLE(MyFrame, wxFrame)
        EVT_TEXT_ENTER(TestInputFieldID,MyApp::TestVoc)// Wenn Enter gedrückt wird, wird die Funktion aufgerufen.
    END_EVENT_TABLE()
    
    // Create a new application object: this macro will allow wxWindows to create
    // the application object during program execution (it's better than using a
    // static object for many reasons) and also declares the accessor function
    // wxGetApp() which will return the reference of the right type (i.e. MyApp and
    // not wxApp)
    IMPLEMENT_APP(MyApp)
    
    // ============================================================================
    // implementation
    // ============================================================================
    
    // ----------------------------------------------------------------------------
    // the application class
    // ----------------------------------------------------------------------------
    
    // 'Main program' equivalent: the program execution "starts" here
    bool MyApp::OnInit()
    {
        // create the main application window
        MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
                                     wxPoint(50, 50), wxSize(450, 340));
    
        // and show it (the frames, unlike simple controls, are not shown when
        // created initially)
        frame->Show(TRUE);
    
        // Das Textfeld wird erzeugt:
        TestInputField = new wxTextCtrl(frame,TestInputFieldID," ",wxPoint(170,140),
                         wxSize(160,45),0,wxTextValidator(wxFILTER_NONE,&TestValue)); 
        TestInputField->Show(TRUE);
    
        // success: wxApp::OnRun() will be called which will enter the main message
        // loop and the application will run. If we returned FALSE here, the
        // application would exit immediately.
        return TRUE;
    }
    
    // ----------------------------------------------------------------------------
    // main frame
    // ----------------------------------------------------------------------------
    
    // frame constructor
    MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
           : wxFrame(NULL, -1, title, pos, size, style)
    {
    }
    

    Ich habe echt keine Ahnung mehr an was es liegen könnte und würde mich über hilfe sehr freuen.

    MfG Max



  • *push*



  • Master_Max schrieb:

    *push*

    👎



  • Ich gebe dir ja recht, man soll es nicht tuen,
    (Erst recht nicht nach der kurzen Zeit)
    doch im moment weis ich einfach nicht weiter.



  • Ich fasse noch einmal das wichtigste zusammen:

    Die ID für das Texteingabefeld.(wxTextCtrl)

    // IDs for the controls and the menu commands
    enum{
        TestInputFieldID
    };
    

    Das Eventtable

    BEGIN_EVENT_TABLE(MyFrame, wxFrame)
        EVT_TEXT_ENTER(TestInputFieldID,MyApp::TestVoc)// Wenn Enter gedrückt wird, wird die Funktion aufgerufen.
    END_EVENT_TABLE()
    

    Die Methode in der ich die Strings Teste. (Sie wird aufgerufen wenn im Textfeld Enter gedrückt wird

    // Define a new application type, each program should derive a class from wxApp
    class MyApp : public wxApp
    {
    public:
        virtual bool OnInit();
    
        // Die Methode die testet ob der inhalt des wxStrings dem vom std::string entspricht
        void TestVoc()
        {
            if(TestValue.compare( stdString.c_str() ) == 0){
                wxMessageBox("equal");
            }
        }
        MyApp():stdString("Hello"){}
    private:
        string stdString; // der std::string
        wxTextCtrl *TestInputField;// Das Textfeld
        wxString TestValue;// Hier sollte der Inhalt des Textfeldes gespeichert werden.
    
    };
    

    Und die Hauptmethode:

    // 'Main program' equivalent: the program execution "starts" here
    bool MyApp::OnInit()
    {
        // create the main application window
        MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
                                     wxPoint(50, 50), wxSize(450, 340));
    
        // and show it (the frames, unlike simple controls, are not shown when
        // created initially)
        frame->Show(TRUE);
    
        // Das Textfeld wird erzeugt:
        TestInputField = new wxTextCtrl(frame,TestInputFieldID," ",wxPoint(170,140),
                         wxSize(160,45),0,wxTextValidator(wxFILTER_NONE,&TestValue));
        TestInputField->Show(TRUE);
    
        // success: wxApp::OnRun() will be called which will enter the main message
        // loop and the application will run. If we returned FALSE here, the
        // application would exit immediately.
        return TRUE;
    }
    

    Über Hilfe würde ich mich sehr freuen.
    Ich vermute der Fehler liegt im string vergleich.

    MfG Max



  • Hier kennt sich niemand aus. Frag in einem wxWidgets Forum.



  • -> schrieb:

    Hier kennt sich niemand aus. Frag in einem wxWidgets Forum.

    Hmmm, ich kenne einige die sich hier damit auskennen, allerdings werde ich deinen Rat notfalls befolgen.

    Danke.

    MfG Max



  • Hier gehts weiter:
    http://g.yi.org/forum/read.php?13,3766
    [EDIT]Meine Englisch Fehler dürft ihr behalten 🤡 [/EDIT]

    MfG Max


Anmelden zum Antworten