User forums > Using Code::Blocks

cout redirection problem: wxWidgets 2.8.7, MinGW, Windows XP

(1/2) > >>

MattPhillips:
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

Biplab:
Definitely this problem is with wx; not with C::B.

BTW why have you added the poll?? :?:

MattPhillips:
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

Biplab:

--- Quote from: MattPhillips on June 16, 2008, 04:34:43 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. 

--- End quote ---

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?

MattPhillips:
Just to be clear--I had no intention of posting a poll, I just followed the defaults.

Best,
Matt

Navigation

[0] Message Index

[#] Next page

Go to full version