我正在尝试编写一段代码以使用带有 Qt 的 c++ 连接到 FTP 服务器,但我看到了一些奇怪的结果。代码如下
void eos::WeatherRadar::connectToServer()
{
m_bomServer = new QFtp;
connect( m_bomServer, SIGNAL( commandStarted( int ) ), this, SLOT( serverConnectStarted() ) );
connect( m_bomServer, SIGNAL( commandFinished( int, bool ) ), this, SLOT( serverConnectFinished() ) );
m_bomServer->connectToHost("ftp.bom.gov.au");
m_bomServer->connectToHost("ftp.bom.gov.au");
if ( m_bomServer->hasPendingCommands() )
std::cout << "I have commands to execute..." << std::endl;
else
std::cout << "I have no commands even though you just gave me one... WTF!!!" << std::endl;
}
现在让奇怪的开始......注意我已经重复了这connectToHost
行。出于某种原因,如果我只在它说“即使你给了我一个命令我也没有命令...... WTF !!!”时才打那个电话 只有当我两次调用时才会hasPendingCommands()
返回true
。此外,无论我拨打一次还是两次,commandStarted(int)
都不会发出信号。
有谁知道为什么会发生这种情况或如何解决?在此先感谢大家:-)。