I created a button and a textbrowser via gui drag&drop. the ui is created in the mainwindow.cpp as well as the click-button-function. There is a main.cpp but thats irrelevant cause the program shall not start until the startbutton is clicked.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "myserver.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_startButton_clicked()
{
MyServer mServer;
}
This is all fine so far, the problem is in the myServer.cpp where I want to write something into the textBrowser via ui->textBrowser->append("hello hello");
. but the myServer.cpp class doesn't "know" the ui. "ui" not declared identifier
#include "myserver.h"
#include "mainwindow.h"
MyServer::MyServer(QObject *parent) :
QObject(parent)
{
}
void MyServer::newConnection()
{
server = new QTcpServer(this);
connect(server,SIGNAL(newConnection()),this,SLOT(newConnection()));
int ports = MainWindow::port();
if(!server->listen(QHostAddress::Any,ports))
{
}
else
{
//here is the problem
ui->textBrowser->append("hallo hallo");
}
}
normaly i would create a new (for example)
MainWindow test;
and call functions via this test.function();
but this does not work here?