Hi,
I'm redirecting cout output to a TextView, but I've a strange problem.
I'm setting up the cout redirection in my constructor of my Window object (I'm using GTKmm as UI lib, in combination with Glademm)
Code:
// Set up our own stream buffer
// First get the text buffer from the TextView
Gtk::TextView * textview = 0;
this -> glade_ref -> get_widget("txtLog", textview);
this -> stream_buffer = new TextViewStreamBuffer<char>;
this -> stream_buffer -> set_text_buffer(textview -> get_buffer());
std::cout.rdbuf(dynamic_cast<std::streambuf *>(this -> stream_buffer));
This is my custom cout streambuf:
Code:
/**
* DLDI GUI Patcher for Linux
*
* This program is an easy to use GUI to patch multiple files at once,
* created with GTKmm and intended voor Linux users
*
* Created by Lucas van Dijk, using an modified version of dldi source,
* by Michael Chisholm (Chishm)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @author Lucas van Dijk
* @author Micheal Chisholm
* @version $Id$
* @license http://www.opensource.org/licenses/gpl-license.php
*/
#ifndef TEXTVIEWSTREAM_H_INCLUDED
#define TEXTVIEWSTREAM_H_INCLUDED
#include "stdinc.h"
template <class charT = char, class traits = std::char_traits<charT> >
class TextViewStreamBuffer : public std::basic_streambuf<charT, traits>
{
protected:
// Members
Glib::RefPtr<Gtk::TextBuffer> buffer;
/**
* This functions gets called when the << operator is used, and so we want to put the contents
* in our TextView.
*/
std::streamsize xsputn(const charT * text, std::streamsize length)
{
if (this -> buffer)
{
this -> buffer -> insert(this -> buffer -> end(), Glib::ustring(text));
return static_cast<std::streamsize>(this -> buffer -> size());
}
else
{
return 0;
}
}
public:
TextViewStreamBuffer() : buffer(0) { }
/**
* Sets our text buffer so we know what textview we need to use
* @param buffer The TextBuffer object of the TextView
*/
void set_text_buffer(Glib::RefPtr<Gtk::TextBuffer> buffer)
{
this -> buffer = buffer;
}
};
#endif
But now my problem, it quits redirecting after two cout's. I see to lines of cout's in my TextView, but there should be much more.
here is a piece of code where I cout:
Code:
// Iterate through all files
for(unsigned int i = 0; i < files.size(); i++)
{
// Get extension
std::string::size_type dot_position = files[i].find_last_of('.');
if(dot_position == std::string::npos)
{
// It's a directory, skip it
continue;
}
std::string extension = files[i].substr(dot_position, files[i].length());
// If it's al DLDI File...
if(extension == ".dldi")
{
// .. load it and add it to the combobox
DLDIFile * dldi_file = new DLDIFile(files[i]);
this -> dldi_files.push_back(dldi_file);
std::cout << "Found DLDI File, Driver name: " << files[i] << "fdg" << std::endl;
// Add to combo
row = *(this -> combo_model -> append());
row[this -> columns.text] = dldi_file -> get_driver_name();
}
}
This function (it's not the complete function), iterates through all files, and adds all files with the .dldi extension to a combobox. It also cout something, so something is shown up in the log.
There are 3 files in my directory, so in my log, there should be 3 times
Found DLDI File, Driver name: {filename}
But, there is only one, and 'fdg' doesn't show up too.
Any ideas why it's acting so strange?