Note that there are some explanatory texts on larger screens.

plurals
  1. POQT readReady() TCPSocket no recieving message until after it is needed
    text
    copied!<p>This is Homework so just some conceptual tips woudl be nice.</p> <p>At the Moment im creating a client server project, the client will send a message to the server(this part works great), but then the server sends a message back to the client and this is where I begin to have issues, I have created a separate class in QT called Connection Management in my client that deals with sending a receiving messages, this class is used by my Controller class, which handle the Application logic of all my UI Pages, now when my controller, sends a message to the server a message is sent back, atm I have it as an echo, my ConnectionManagement class handles Incomming messages with the readyRead() signal, the problem here is when someone is using my client and say press the next button, the next button slot will be called, and wait until after execution of NextButtonPressed() or w/e. until the read ready notices, there is something being sent back to it, i tried having a read i can call manually but it doesn't appear to work any suggestions? </p> <p>a small bit of my code:</p> <pre><code>ConnectionManager.cpp ConnectionManager::ConnectionManager(QObject *parent) : QTcpServer(parent) { socket = new QTcpSocket(this); connect(socket, SIGNAL(readyRead()), this, SLOT(readyread())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnect())); socket -&gt; connectToHost("192.168.0.119",60000); } QString ConnectionManager::getMessage() { //sleep(1); while (inMessage == "") { //my attempt at calling read() manually it will read nothing QByteArray data = socket-&gt;readAll(); //just checkign what i am getting my server will immediately return a trivial //string i.e "carly, santos, andrew, bob" std::cout &lt;&lt; data.data() &lt;&lt; "+ 8" &lt;&lt; std::endl; inMessage = data; } return inMessage; } void ConnectionManager::sendMessage(QString &amp;message) { socket -&gt; write(message.toUtf8()); } //my socket for reading whenever something is sent? void ConnectionManager::readyread() { QByteArray data = socket-&gt;readAll(); inMessage = data; std::cout &lt;&lt; data.data() &lt;&lt; "+ 1" &lt;&lt; std::endl; } </code></pre> <p>ok now my controller.cpp</p> <pre><code>void Controller::openTALogin() { //TODO send message to Server QString buffer = Fill::fillBufferState("Client", "TA"); //std::cout &lt;&lt; buffer.toUtf8().data() &lt;&lt; std::endl; myConnection-&gt;sendMessage(buffer); // &lt;- this works great =) //sleep(7); std::cout &lt;&lt; "1234" &lt;&lt; std::endl; QString in = myConnection -&gt; getMessage(); //&lt;- gets nothing -.- std::cout &lt;&lt; in.toUtf8().data() &lt;&lt; "+ 12" &lt;&lt; std::endl; //TODO recieve List from server //ForNow QLinkedList&lt;QString&gt; *testList = new QLinkedList&lt;QString&gt;(); Fill::fillLinkedList(testList, in); //testList -&gt; push_front("jabba:5:hut:1"); //testList -&gt; push_front("blind:3:mice:2"); //testList -&gt; push_front("eat:5:day:3"); //testList -&gt; push_front("hello:4:goodbye:4"); delete userWindow; taLoginWindow = new TALoginWindow(this, testList); taLoginWindow -&gt; show(); testList -&gt; clear(); delete(testList); </code></pre> <p>}</p> <p>the message is received here after this function executes, i remember form using C-Style TCP/IP connection the read would wait until there is data to continue, but it seems for be cool with getting nothing here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload