QFtp hasPendingCommand() 返回 true,但从不发出 commandStarted(int) 信
QFtp hasPendingCommands() returns true, but never emits commandStarted(int) signal
我正在尝试编写一段代码以使用带有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)
信号。
有没有人知道为什么会发生这种情况或如何解决它?提前感谢大家:-)。
QFtp::hasPendingCommands 的文档说
正在执行的命令不被视为计划 命令。
因此,在调用connectToHost()
后立即为假是正常的。
对于连接到commandStarted()
从未被调用的插槽的问题,很难从显示的代码中说出来,但一个典型的原因是你的代码没有返回到Qt的主事件循环。QFtp 是异步的,因此如果 Qt 事件循环不运行,则不会发生任何事情。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 'short int'持有的值溢出,但"自动"不会溢出?
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 调用'begin(int [n])'没有匹配函数
- 没有显式声明的int[]中的foreach
- 在c++中访问int到类对象的映射时出错
- 为什么我无法更改"set<set>"循环中的值<int>
- 长 长 int 不要 长 int 好
- C++程序在循环后给出奇怪的int值
- 如何计算数据类型的范围,例如int
- 如果"new int"返回"int*",那么为什么"new int[n]"不返回"int**"?
- QFtp hasPendingCommand() 返回 true,但从不发出 commandStarted(int) 信