GUIドラッグ&ドロップでボタンとテキストブラウザを作成しました。UI は mainwindow.cpp とクリックボタン関数で作成されます。main.cpp がありますが、それは無関係な原因であり、startbutton がクリックされるまでプログラムは起動しません。
#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;
}
これまでのところ問題ありません。問題は myServer.cpp で、何かを経由して textBrowser に書き込もうとしていui->textBrowser->append("hello hello");
ます。しかし、myServer.cpp クラスは 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");
}
}
通常、私は(たとえば)新しいものを作成し、
これMainWindow test;
を介して関数を呼び出しますtest.function();
が、これはここでは機能しませんか?