-1

サーバーとクライアント間の接続を作成しました。接続はコンソールで正常に機能しますが、シグナルとスロットを使用して QTcpServer クラスを GUI に接続できませんでした。これが私のコードです:

サーバーTCP.cpp

ServerTcp :: ServerTcp (QWidget *parent)
{
    listen(QHostAddress::Any,4000);
    QObject:: connect(this, SIGNAL(newConnection()),
    this, SLOT(connectionRequest()));
}

void ServerTcp :: connectionRequest()
 {

    emit IHM_connection(); 
    clientConnection = nextPendingConnection();

    QObject:: connect(clientConnection, SIGNAL(readyRead()),
    this, SLOT(read()));
}

void ServerTcp::read()
{

    QString ligne;
    while(clientConnection->canReadLine())    
    {
        ligne = clientConnection->readLine(); 
        emit IHM_text(ligne);           
    }
    QTextStream text(clientConnection);      


}

ManinWindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QObject::connect(&server,SIGNAL(IHM_connetion()),this,SLOT(connectionRequested()));
    QObject::connect(&server,SIGNAL(read(QString)),this,SLOT(print_text(QString)));
}



void MainWindow::on_quitButton_clicked()
{
    qApp->quit();
}

void MainWindow::print_text(QString text){
     ui->log->append("message : " + text);
}

void MainWindow::connectionRequested(){
    ui->log->append("connection OK!");
}

MainWindow::~MainWindow()
{
    delete ui;
}
4

1 に答える 1