First of all, when you create the MyServer object in the MainWindow::on_StartButtonClicked function, the object needs to be created dynamically, else it will go out of scope and get deleted, but perhaps you're just showing this, rather than its declaration in the MainWindow header.
As to your question, your UI is connected to the MainWindow, so use Qt's signals and slots to connect a signal from the MyServer object to the MainWindow and send it the text to be displayed. Then the MainWindow can add it to the textBrowser. Something like this: -
void MainWindow::on_startButton_clicked()
{
MyServer* mServer = new MyServer;
connect(mServer SIGNAL(updateUI(const QString)), this, SLOT(AppendToBrowser(const QString)));
}
Then instead of calling ui->textBrowser->append("hallo hallo"); in newConnection, emit the signal: -
emit updateUI("hallo hallo");
In MainWindow, you'd have the function AppendToBrowser: -
void MainWindow::AppendToBrowser(const QString text)
{
ui->textBrowser->append(text);
}
Alternatively, you could pass a pointer of the UI object to the MyServer and call it from there, but the signals and slots method is much cleaner.
=========== Edited for headers, in response to comments ======================
//Skeleton My Server header
class MyServer : public QObject
{
QOBJECT
signals:
void updateUI(const QString text);
};
// Skeleton MainWindow header
class MainWindow : public QMainWindow
{
private slots:
void AppendToBrowser(const QString text);
};