title: Printing to an element of MainWindow from an outside class
body: <p>I have created a set of watcher/helper classes that monitor an outside application, and I would like these to print to a log window inside my MainWindow's ui when changes are made. My idea was to create this watcher inside a thread in main, but I am not sure the best way to link it to my MainWindow. I know that simply passing it as below will not work, but am unsure of the proper way to do this, if there even is one, because of Qt's design. Some research indicated to me that it isn't really appropriate to pass MainWindow to an outside class, but I am unsure of a better way to do it.</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      try {
          std::string host = "localhost";
          unsigned short port = 8193;
          MainWindow w;
          w.show();
  
          // Access class for the program that I am watching
          UserInterface ui(host, port);
          // StatePrinter class, which is registered in the UI and will print changes to MainWindow, ideally
          // would I be able to pass something in the StatePrinter constructor to accomplish my goal?
          ui.registerObserver(new StatePrinter(w));
          UiRunner runner(ui);
          boost::thread runnerThread(boost::ref(runner));
  
          w.show();
          QApplication a(argc, argv);
  
          runner.cancel();
          runnerThread.join();
  
          return a.exec();
      } catch(std::exception &amp;ex) {
          // ...
      }
  }
  </code></pre>
  
  <p>I suppose it is a possibility to make this thread inside MainWindow itself, but I prefer having it in main. What would be the best way to link my StatePrinter class to MainWindow?</p>