-1
서버와 클라이언트간에 연결을 만들었지 만 콘솔에서 제대로 작동하지만 신호와 슬롯이있는 GUI에 QTcpServer 클래스를 연결할 수 없습니다. 여기 내 코드입니다 :QTcpServer를 신호로 GUI에 연결하려고 시도했습니다.
ServerTCP.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;
}
코드의 관련 부분 만 게시하십시오. 전체 프로그램을 붙여 넣지 마십시오. – sashoalm
_you_는 무엇이라고 생각하십니까? 다른 사람들에게 코드를 던지기보다는 코드를 디버깅 할 때 약간의 노력을 보여 주어야합니다. – Michael