I have a C++ project where I write a small log file to std::cout. Inside this project I have a main Object that I create and one function that runs the code. A simplified version would look like this:
int main(int argc, char *argv[])
{
std::string pathToSettingsFile(argv[1]);
MainObject m(pathToSettingsFile);
m.run();
}
Now I have developed a Qt GUI for this Application. One of the conditions is, that I cannot use any QT library in my project. (QT is only allowed in the GUI which is at the moment totally independent from the project - basically the GUI only creates a settingsFile which can be loaded by the project)
Is it somehow possible that I redirect std::cout to a QTextBrowser? I thought about simply adding a second input argument which is by default std::cout but if needed it points to QTextBrowser. Like this:
int main(int argc, char *argv[])
{
std::string pathToSettingsFile(argv[1]);
std::ostream &output = std::cout;
MainObject m(pathToSettingsFile, output);
m.run();
}
and If I want to start it from QT I simply add another ostream.
// GUI CODE:
QTextBrowser *tb = new QTextBrowser();
std::ostream myOstream = somehow connect myOstream to tb;
MainObject m(pathToSettingsFile, output);
m.run();
But I have no idea how I can do this, and if this is even possible... It might be that there is another very simple solution to this problem.
Thanks for your feedback