开发者

GUI not responding in Wxwidgets in Multithreaded app

I've been struggling with this code for days. The program is multi-threaded with newly created threads raising events for writing data to main thread. But the program is that the gui becomes non-responsive when the thread calls the event. If I replace the status_brute_text->AppendText(wxT("开发者_开发百科insert")) with some message box which is independent, then the program runs without a problem. Also the thread is passed as both as detachable and joinable, but no difference occurs. I actually plan to open a console app with this thread with wxExecute and output its output to gui. Any help would be greatly appreciated.

Thanking you in advance....

testerFrame::testerFrame(wxFrame *frame)
    : GUIFrame(frame)
{
#define thread_adder 10

#if wxUSE_STATUSBAR
    statusBar->SetStatusText(_("John the ripper GUI"), 0);
    statusBar->SetStatusText(wxbuildinfo(short_f), 1);
#endif
    this->Connect(wxID_ANY,wxEVT_COMMAND_TEXT_UPDATED,
     wxCommandEventHandler(testerFrame::insert));
}

testerFrame::~testerFrame()
{
}

void testerFrame::insert(wxCommandEvent &event)
{
 status_brute_text->AppendText(wxT("insert"));
}

void testerFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void testerFrame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void testerFrame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void testerFrame::configure(wxCommandEvent &event)
{
    wxString msg = wxT("Will be implemented later");
    wxMessageDialog *dialog = new wxMessageDialog(0L,msg,_("hia"),wxYES_NO);
    dialog->ShowModal();
}

void testerFrame::select_pass_file( wxCommandEvent& event )
{

if(m_filePicker2->GetPath().IsEmpty())
{
    return;
}
}

void testerFrame::start_john(wxCommandEvent &event)
{
    /*wxArrayString output,output2;
    wxString command = wxString(wxT("john --incremental --session:jvc")) + m_filePicker2->GetPath();
    wxMessageBox(command);
    wxExecute(command,output);*/
    MyThread *th = new MyThread(this);
    th->Create();
    th->Run();
}

void *MyThread::Entry()
{

    // notify the main thread
    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, wxID_ANY);
    event.SetInt(1);
     // pass some data along the event, a number in this case
    m_parent->GetEventHandler()->AddPendingEvent( event );
    return 0;
}


Problem:

AppendText() generates a wxEVT_COMMAND_TEXT_UPDATED, which causes testerFrame::insert() to be called which calls AppendText() which generates another wxEVT_COMMAND_TEXT_UPDATED.....

From wxWidgets Documentation:

...a wxEVT_COMMAND_TEXT_UPDATED event, [is] generated when the text changes. Notice that this event will be sent when the text controls contents changes - whether this is due to user input or comes from the program itself (for example, if SetValue() is called); see ChangeValue() for a function which does not send this event

Solution:

Use ChangeValue( status_brute_text->GetValue() + "insert" ) instead of AppendText( "insert" ).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜