Weird of TCP client read function
-
Hello , I was successfully build a TCP client with QTcpSocket and it works fine both read and write data.
However when I move my connect tcp code from mainwindow constructor to the pushbutton clicked slot function
I can't read the data from server end anymore !! I have no idea what's happened...
I wanna switch tcp connection on and off and also update IP address when I clicked the button.Here is the code :
in mainwindow constructor or on_clicked_connectBtn()if(handler->Connect()){ qDebug() << "success"; }else{ qDebug() << "fail"; }here is the code in handler->connect()
bool Handler::connect{ this->Socket = new QTcpSocket(); this->Socket->ConnectToHost(ip, port); connect(this->Socket, SIGNAL(readyRead()), this, SLOT(Read)); return Socket->waitForConnect(); }and just
qDebug() << this->Socket->readAll();in the Read() function.
thx~
-
Hi
But does it connect?
qDebug() << "success";
Should not make any difference when moved from constructor :) -
Hi,
Maybe a silly question but did you lose a set of parenthesis on your slot when moving your code in your connect statement ?
-
Hi
But does it connect?
qDebug() << "success";
Should not make any difference when moved from constructor :) -
Hi,
Maybe a silly question but did you lose a set of parenthesis on your slot when moving your code in your connect statement ?