首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Qt开发FTPClient时出现的问题

使用Qt开发FTPClient时出现的问题
EN

Stack Overflow用户
提问于 2010-12-01 20:07:58
回答 5查看 5.1K关注 0票数 6

我正在尝试使用QT网络实现FTPClient。

如何处理下载过程中出现的异常情况,如网线拔出、网络连接中断等。?

我的FTPClient怎么才能知道这样的事件,有没有这样的通知?

我尝试过使用done( bool ),ommandFinished ( int id,bool error )这样的信号,但是我没有得到任何类型的信号。

EN

回答 5

Stack Overflow用户

发布于 2010-12-01 22:34:37

您似乎在使用QFtp,它已经过时了。您应该使用QNetworkReply (和QNetworkAccessManager),它有QNetworkReply documentation ()和error()信号。

票数 4
EN

Stack Overflow用户

发布于 2010-12-11 01:29:28

您是否尝试过创建自定义插槽并将其连接到QNetworkReply错误信号?

然后,您可以检查参数以确定错误,并决定如何处理它。

代码语言:javascript
复制
QNetworkReply::NoError  0   no error condition. Note: When the HTTP protocol returns a redirect no error will be reported. You can check if there is a redirect with the QNetworkRequest::RedirectionTargetAttribute attribute.
QNetworkReply::ConnectionRefusedError   1   the remote server refused the connection (the server is not accepting requests)
QNetworkReply::RemoteHostClosedError    2   the remote server closed the connection prematurely, before the entire reply was received and processed
QNetworkReply::HostNotFoundError    3   the remote host name was not found (invalid hostname)
QNetworkReply::TimeoutError 4   the connection to the remote server timed out
QNetworkReply::OperationCanceledError   5   the operation was canceled via calls to abort() or close() before it was finished.
QNetworkReply::SslHandshakeFailedError  6   the SSL/TLS handshake failed and the encrypted channel could not be established. The sslErrors() signal should have been emitted.
QNetworkReply::TemporaryNetworkFailureError 7   the connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established.
QNetworkReply::ProxyConnectionRefusedError  101 the connection to the proxy server was refused (the proxy server is not accepting requests)
QNetworkReply::ProxyConnectionClosedError   102 the proxy server closed the connection prematurely, before the entire reply was received and processed
QNetworkReply::ProxyNotFoundError   103 the proxy host name was not found (invalid proxy hostname)
QNetworkReply::ProxyTimeoutError    104 the connection to the proxy timed out or the proxy did not reply in time to the request sent
QNetworkReply::ProxyAuthenticationRequiredError 105 the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any)
QNetworkReply::ContentAccessDenied  201 the access to the remote content was denied (similar to HTTP error 401)
QNetworkReply::ContentOperationNotPermittedError    202 the operation requested on the remote content is not permitted
QNetworkReply::ContentNotFoundError 203 the remote content was not found at the server (similar to HTTP error 404)
QNetworkReply::AuthenticationRequiredError  204 the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)
QNetworkReply::ContentReSendError   205 the request needed to be sent again, but this failed for example because the upload data could not be read a second time.
QNetworkReply::ProtocolUnknownError 301 the Network Access API cannot honor the request because the protocol is not known
QNetworkReply::ProtocolInvalidOperationError    302 the requested operation is invalid for this protocol
QNetworkReply::UnknownNetworkError  99  an unknown network-related error was detected
QNetworkReply::UnknownProxyError    199 an unknown proxy-related error was detected
QNetworkReply::UnknownContentError  299 an unknown error related to the remote content was detected
QNetworkReply::ProtocolFailure  399 a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.)

其中一些错误代码特定于HTTP,但其他错误代码更为通用。

票数 3
EN

Stack Overflow用户

发布于 2010-12-09 20:41:03

要在使用QFtp时处理网络异常,可以监听stateChanged()信号。如果状态变为Closing或Unconnected,可以检查error()是什么。

关于QNAM与QFtp: QNAM是更干净、更新的应用编程接口,但两者都是为了工作,并且都得到了官方的支持。就API而言,QFtp使用了旧的命令-id模式(每个命令返回一个命令-id),这要求我们跟踪命令(例如:找出信号是为哪个命令发出的)。我发现QNAM的api模式要好得多,因为它的命令返回一个QNetworkReply对象,该对象反过来发出信号。但是,QNAM的api似乎并没有针对ftp进行调整,因为它可以处理http/s (像no deletion of files over ftp),所以也许你现在最好还是坚持使用QFtp。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4324178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档