Author Topic: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP  (Read 9312 times)

Offline MattPhillips

  • Single posting newcomer
  • *
  • Posts: 6
Hello,

I am posting this to both C::B and wxWidgets boards, since I don't know where the problem it is.  Here it is, step by step:

1) I download CB 8.02 with the MinGW compiler and install in C:\CodeBlocks.  (OS: Windows XP)

2) I download wxWidgets (not wxPack) and install it in C:\SourceCode\Libraries\wxWidgets-2.8.7 (default).

3) I go into ...\include\wx\msw\setup.h and set wxUSE_STD_IOSTREAM to 1.  Just for good measure I do the same in setup0.h and setup_microwin.h

4) I create the following .bat file as per the instructions at http://wiki.wxwidgets.org/Compiling_WxWidgets_With_MSYS-MinGW, under "Setting up MinGW"

@echo off
set path=C:\CodeBlocks\MinGW\bin;%PATH%
set LIBRARY_PATH=C:\CodeBlocks\MinGW\lib
set C_INCLUDE_PATH=C:\CodeBlocks\MinGW\include
set CPLUS_INCLUDE_PATH=C:\CodeBlocks\MinGW\include\c++\3.4.5;C:\CodeBlocks\MinGW\include\c++\3.4.5\backward;C:\CodeBlocks\MinGW\include\c++\mingw32;C:\CodeBlocks\MinGW\include

5) I name this 'ConfigWX.bat' and put it in C:\SourceCode\Libraries\wxWidgets-2.8.7.

6) I open up the command line and cd C:\SourceCode\Libraries\wxWidgets-2.8.7, and then run ConfigWX.bat.

7) I enter gcc -v to make sure MinGW sees the directory; it does.

8 ) I cd build\msw and first run MinGW with the 'clean' option, since by now I have compiled and re-compiled several times:

mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=0 USE_OPENGL=1 clean

Running this takes about a minute.

9) Now I compile:

mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=0 USE_OPENGL=1

This takes about a half-hour.

10) Open C::B, using the wxWidgets default template, and modify the App.cpp file so that it cout is redirected to a wxTextCtrl I create, using wxTextCtrl:

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "testTextApp.h"
#include "testTextMain.h"#include <wx/textctrl.h>
#include <iostream>
using namespace std;

IMPLEMENT_APP(testTextApp);

bool testTextApp::OnInit()
{
    testTextFrame* frame = new testTextFrame(0L);
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();

    wxTextCtrl* textctl = new wxTextCtrl(frame, wxID_ANY);
    wxStreamToTextRedirector redirect(textctl);

    cout << "Please work...\n";

    textctl->Show();
    return true;
}

When I do this I get "error: 'wxStreamToTextRedirector' was not declared in this scope".  Note that I have included <wx/textctrl.h>, which is the only #includelisted in the wxStreamToTextRedirector doc page.

11) Trying to redirect using rdbuf() also doesn't work; the following includes test cut and pasted from the wxTextCtrl doc page:

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "testTextApp.h"
#include "testTextMain.h"
#include <wx/textctrl.h>
#include <iostream>
using namespace std;

IMPLEMENT_APP(testTextApp);

bool testTextApp::OnInit()
{
    testTextFrame* frame = new testTextFrame(0L);
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();

    wxTextCtrl* textctl = new wxTextCtrl(frame, wxID_ANY);
    textctl->Show();

    streambuf *sbOld = cout.rdbuf();
    cout.rdbuf(*textctl);

    cout << "To TextCtrl\n" << endl;

    cout.rdbuf(sbOld);

    cout << "To console\n";

    return true;
}

Now the error, at 'cout.rdbuf(*textctl);' is:

error: no matching function for call to `std::basic_ostream<char, std::char_traits<char> >::rdbuf(wxTextCtrl&)'|

This happens even when I include

#define NO_TEXT_WINDOW_STREAM

in the textctrl.h file.

*********************************************************************

So, what is going on?! Apparently nobody else is having this problem, but I can't figure out what's going on.  It seems particularly strange that wxStreamToTextRedirector isn't even defined in textctrl.h.

Best,
Matt
« Last Edit: June 16, 2008, 04:24:43 pm by MattPhillips »

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #1 on: June 16, 2008, 04:08:42 pm »
Definitely this problem is with wx; not with C::B.

BTW why have you added the poll?? :?:
Be a part of the solution, not a part of the problem.

Offline MattPhillips

  • Single posting newcomer
  • *
  • Posts: 6
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #2 on: June 16, 2008, 04:34:43 pm »
Hi,

It's my first time on this board and it wouldn't let me post unless I selected two 'options'.  I really had no idea what it meant so I just put in keywords. 

Best,
Matt

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #3 on: June 16, 2008, 04:44:22 pm »
It's my first time on this board and it wouldn't let me post unless I selected two 'options'.  I really had no idea what it meant so I just put in keywords. 

I see. Aparently most newbies are posting a poll. May be it's the reason behind. Thanks for posting it.

@Yiannis, Thomas: Can we fix this?
Be a part of the solution, not a part of the problem.

Offline MattPhillips

  • Single posting newcomer
  • *
  • Posts: 6
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #4 on: June 16, 2008, 04:47:42 pm »
Just to be clear--I had no intention of posting a poll, I just followed the defaults.

Best,
Matt

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #5 on: June 16, 2008, 04:58:08 pm »
Just to be clear--I had no intention of posting a poll, I just followed the defaults.

To clear my previous message, I was glad to know the problem other users faces. :)
Be a part of the solution, not a part of the problem.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9699
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #6 on: June 16, 2008, 05:03:28 pm »
@Yiannis, Thomas: Can we fix this?
Nothing to fix here, really.

If guys click on "Create new poll" instead of "Create new topic" we cannot do anything about that. Creating a new topic as newbie (first topic posted ever) just works fine.

Edit:
Thomas: As a newbie I was in fact still able to create a poll. So this "feature" of yours to avoid this does not work. ;-)
« Last Edit: June 16, 2008, 05:16:46 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MattPhillips

  • Single posting newcomer
  • *
  • Posts: 6
Re: cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP
« Reply #7 on: June 16, 2008, 05:37:47 pm »
Okay, I get it... Oops... 8 pt. text isn't easy to read on my laptop, what can I say...

Best,
Matt