Ok... this is really getting aggravating. The only solution I have found so far is to use QTcpSocket.flush(). But even if I set up a signal and socket connection to handle the signal this should generate, nothing happens. So it is time to post some code.
Here is the code that generates the tcp socket. It is part of "main" because my splash screen contains the login screen and the login data to send is generated there. w is the main window class instance while a is the application class
@
int main(int argc, char *argv[])
{
// creates splash
// detects network configuration ... saves in w
// loads application settings... saves in w
// handles arguments
// shows login widgets and waits for user input
...
while (waitForResponse)
{
QTcpSocket loginSocket;
if (w.getServerAddress() == QString("LOCAL"))
loginSocket.connectToHost(w.getHostAddressIn()->toString(), (quint16)ServerPorts::loginRequest);
else
loginSocket.connectToHost(*w.getServerAddress(), (quint16)ServerPorts::loginRequest);
// generate datastream using username and password
// code for connecting the socket which works fine...
// HERE is the code that calls the code that doesn't get a response...
w.sendLoginData(dataStream->data(), &loginSocket);
while (w.isSendingLogin())
a.processEvents(); // THE PROGRAM NEVER LEAVES THIS LOOP
...
}
...
}
@
Here are the two functions called by the previous code. It may be important to note that the client engine class referred to is in a separate dll and namespace. My guess is that fact separates the code from the main window's event loop.
@
bool MyWindow::isSendingLogin() { return mClientEngine->isSendingData(); }
void MyWindow::sendLoginData(const char* data, QTcpSocket* socket)
{
if (mClientEngine == NULL)
mClientEngine = new ClientEngine(this);
mClientEngine->sendDataToServer(data, socket);
}
@
Here is the code from the dynamically loaded engine called by the above functions. This includes the code that performs the flush AND the slot that is supposed to be called as a result.
@
void ClientEngine::sendDataToServer(const char* data, QTcpSocket* socket)
{
mBytesSentCount = 0;
mOutgoingSocket = (QTcpSocket*)socket;
connect(socket, SIGNAL(bytesWritten(qint64 bytes)), this, SLOT(dataSent(qint64 bytes)));
mOutgoingByteCount = socket->write(data);
socket->flush();
}
void ClientEngine::dataSent(qint64 bytes) // SLOT referred to in above connection that NEVER GETS CALLED
{
mBytesSentCount += bytes;
if (mBytesSentCount >= mOutgoingByteCount)
{
disconnect(mOutgoingSocket, SIGNAL(bytesWritten(qint64 bytes)), this, SLOT(dataSent(qint64 bytes)));
mOutgoingSocket = NULL;
}
}
bool ClientEngine::isSendingData() const { return mOutgoingSocket != NULL; }
@
My best guess is that because the engine is in a separate dll, that somehow its signals are being left out of the event loop... Not sure how I would fix that... or if it is even the problem.