hy,
I found out, that gtkmm is delaying the output I wrote to std::cerr/std::cout until the Gtk::Window is closed.
But after a bit of researching I found out, that this is not always true. For example, if I add a Button to the Window, and I show the button, outputs on STDOUT and STDERR are working as exepcted.
To test this, I have written an MWE: (If you uncomment the line _button.show();, you would see, that output is not delayed. But if you don't show the button, the output is delayed, until the window is closed.)
Also I have addedd a ofstream, which outputs the contents in both cases directly to /tmp/test.
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/application.h>
#include <fstream>
#include <iostream>
class window_t : public Gtk::Window {
public:
window_t(void);
private:
Gtk::Button _button;
};
window_t::window_t(void): _button("Click ME") {
add(_button);
//_button.show();
std::cerr << "construct-cerr" << std::endl;
std::cout << "construct-cout" << std::endl;
std::cout.flush();
std::cerr.flush();
std::ofstream file("/tmp/test");
file << "construct-file" << std::endl;
file.close();
}
int main(int argc, char* argv[]) {
auto app = Gtk::Application::create(argc, argv, "com.example.test");
window_t gtkmm_window;
return app->run(gtkmm_window);
}
You can compile this code by:
g++ main.cpp -o main `pkg-config --cflags --libs gtkmm-3.0` -Wall -pedantic -Wextra -Werror -Wcast-qual -Wcast-align -Wconversion -fdiagnostics-color=auto -g -O2 -std=c++11
Why does gtkmm delay outputs to STD(OUT|ERR) and how can I prevent this?
I am using gcc version 4.9.2 and gtkmm 3.14.
Aucun commentaire:
Enregistrer un commentaire