QTcpClient successfully connects, but not to my server. Where is it connecting?

纵然是瞬间 提交于 2019-12-03 08:42:15

While QTEST_MAIN creates a QApplication and runs all your tests, it does so sequentially and not with an event loop. Therefore, while your socket can indeed connect to the server (meaning qTestSocket->waitForConnected() returns true), since the app doesn't return to an event loop, the QTcpServer's signal will not get emitted, and TcpCommSocketTest::connectDummyServer() never gets called.

Try adding a call to qApp->processEvents() at the end of initTestCase(). It should let connectDummyServer() be called.

You could be connecting to an instance of the server started earlier. Poke around with a process monitor to make sure you don't have any stray instances. Does your test setup automatically kick off and shutdown the dummy server? It could be that the test is succesfully starting the server, but failing to kill it.

Also, from the 127.0.0.1, the dummy server is running on the same machine as the test code right?

Verify the return value of qDummyServer->listen(). It should return true if the server is indeed listening at port 9000. If it returns false, chances are port 9000 is blocked by another process, and it couldn't listen. In that case, your qTestSocket connected to that other process instead of your own server.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!