Pipe printf to modeless window Topic is solved

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
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Pipe printf to modeless window

Post by widgeter »

In my old code, I use printf for tracing purpose. I want to show these trace log in the separate modeless window in real time. What is the best and easiest way of doing this in wxWidgets?
Thanks in advance.
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi »

Did you already look at wxLog?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

under MSW i prefer ::wxLogDebug() together with DebugView:
http://www.sysinternals.com/Utilities/DebugView.html
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Post by widgeter »

Avi wrote:Did you already look at wxLog?
Hi Avi, I have looked at the relevant documentation, but there are quite a few of them. All seems to be ok for the job. I don't know which one (or what combination) is the best and easiest. Although I have to said I am not completely understand them. :oops:
Last edited by widgeter on Sun Jun 18, 2006 1:55 pm, edited 1 time in total.
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Post by widgeter »

doublemax wrote:under MSW i prefer ::wxLogDebug() together with DebugView:
http://www.sysinternals.com/Utilities/DebugView.html
Thanks doublemax, but is the DebugView portable? eg, do I get this in Linux?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

widgeter wrote:
doublemax wrote:under MSW i prefer ::wxLogDebug() together with DebugView:
http://www.sysinternals.com/Utilities/DebugView.html
Thanks doublemax, but is the DebugView portable? eg, do I get this in Linux?
DebugView is Windows only, i don't know if there is any equivalent for other platforms.
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Post by widgeter »

Thanks again doublemax.

I have had a go with wxLogWindow. It seems to be the closest thing I want.
I instantiate a wxLogWindow by:

Code: Select all

    wxLogWindow logWindow(NULL, "Trace");
When I debug the program, it generates an Unhandled exception from

Code: Select all

wxTextPos wxTextCtrl::GetLastPosition() const
The following is the stack trace when it happens:
  • dialogs.exe!wxTextCtrl::GetLastPosition() Line 1170 + 0x11 bytes C++
    dialogs.exe!wxLogWindow::DoLogString(const char * szString=0x00f3df4c, __int64 __formal=1150640749) Line 648 + 0x10 bytes C++
    dialogs.exe!wxLog::DoLog(unsigned long level=6, const char * szString=0x0096a2e8, __int64 t=1150640749) Line 499 C++
    dialogs.exe!wxLogWindow::DoLog(unsigned long level=6, const char * szString=0x0096a2e8, __int64 t=1150640749) Line 639 C++
    dialogs.exe!wxLog::OnLog(unsigned long level=6, const char * szString=0x0096a2e8, __int64 t=1150640749) Line 154 C++
    dialogs.exe!wxVLogDebug(const char * szFormat=0x008a5110, char * argptr=0x018afdd8) Line 310 + 0x7b bytes C++
    dialogs.exe!wxLogDebug(const char * szFormat=0x008a5110, ...) Line 310 + 0x17 bytes C++
    dialogs.exe!wxMutexInternal::Unlock() Line 259 + 0x2e bytes C++
    ....snip
It starts from the wxLogLastError of the following code:

Code: Select all

wxMutexError wxMutexInternal::Unlock()
{
    if ( !::ReleaseMutex(m_mutex) )
    {
        wxLogLastError(_T("ReleaseMutex()"));

        return wxMUTEX_MISC_ERROR;
    }

    return wxMUTEX_NO_ERROR;
}
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

what's the lifetime of your wxLogWindow? it looks like you create it on the stack.

Try:

Code: Select all

wxLogWindow *logWindow=new wxLogWindow(NULL, wxT("Trace"));
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Post by widgeter »

You have solved my problem! Good man.. Thanks :)

Btw, what is the benefit of having "wxT" prepend to the string in wxT("Trace")?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

widgeter wrote:Btw, what is the benefit of having "wxT" prepend to the string in wxT("Trace")?
From the documentation:
wxT() is a macro which can be used with character and string literals (in other words, 'x' or "foo") to automatically convert them to Unicode in Unicode build configuration
Basically it makes sure that it compiles in both unicode and non-unicode builds
widgeter
Knows some wx things
Knows some wx things
Posts: 37
Joined: Sat Jun 10, 2006 11:35 pm

Post by widgeter »

Thanks guy, I was waiting to fix all the problem and post this to everyone, so I can mark it as solved.

My solution to this is by having a combination of wxLogWindow and wxLogDebug. Basically all printf will be relayed to wxLogDebug, and you will get all the output from the wxLogWindow automatically. Sweet!

If you are working on a multiple thread app. Look at the my other post "SendMessage causing deadlock!". The sample provided by micros is excellent!
Post Reply