server to client send data
-
I have two QT projects.One of them is for client other is for server.I add +network both
pro files.I want to write something server to client.So I decided to write from server side , read from client side.
In CLIENT SIDE constructor I have
Client::Client() { tcpSocket = new QTcpSocket(); tcpSocket->connectToHost(QHostAddress::LocalHost,45442);//Connection is OK connect(tcpSocket,&QTcpSocket::readyRead, this, &Client::readyRead);//Not working }
In CLIENT SIDE readyRead()
void Client::readyRead(){ qDebug() << "///READYREAD SLOT///"; qDebug() << tcpSocket->readAll(); }
In server side header file I have
QTcpSocket *clientConnection;
IN SERVER SIDE I HAVE :TimerSlot()
void MainWindow::TimerSlot(){// clientConnection->write(QByteArray::fromStdString("ABCDEFFGHJKL")); }
IN SERVER SIDE CONSTRUCTOR
MainWindow::MainWindow (QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { timerTarget = new QTimer(this); connect(timerTarget,SIGNAL(timeout()),this,SLOT(TimerSlot())); timerTarget->start(700);//NOT WORKINNG All app is shutting down suddenly when I call this code line }
So what is the problem? Where is my error?
Thank you. -
I have two QT projects.One of them is for client other is for server.I add +network both
pro files.I want to write something server to client.So I decided to write from server side , read from client side.
In CLIENT SIDE constructor I have
Client::Client() { tcpSocket = new QTcpSocket(); tcpSocket->connectToHost(QHostAddress::LocalHost,45442);//Connection is OK connect(tcpSocket,&QTcpSocket::readyRead, this, &Client::readyRead);//Not working }
In CLIENT SIDE readyRead()
void Client::readyRead(){ qDebug() << "///READYREAD SLOT///"; qDebug() << tcpSocket->readAll(); }
In server side header file I have
QTcpSocket *clientConnection;
IN SERVER SIDE I HAVE :TimerSlot()
void MainWindow::TimerSlot(){// clientConnection->write(QByteArray::fromStdString("ABCDEFFGHJKL")); }
IN SERVER SIDE CONSTRUCTOR
MainWindow::MainWindow (QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { timerTarget = new QTimer(this); connect(timerTarget,SIGNAL(timeout()),this,SLOT(TimerSlot())); timerTarget->start(700);//NOT WORKINNG All app is shutting down suddenly when I call this code line }
So what is the problem? Where is my error?
Thank you.@ELIF said in server to client send data:
QTcpSocket *clientConnection
where do you new/allocate this ?
-
@ELIF said in server to client send data:
QTcpSocket *clientConnection
where do you new/allocate this ?
@J-Hilk said in server to client send data:
clientConnection
Thank you I forget it:) Now it is working.