在控制台应用程序中使用QFtp [英] Using QFtp in a console app

查看:204
本文介绍了在控制台应用程序中使用QFtp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个高级初学者使用Qt,我试图写一个使用QFtp的控制台应用程序。应用程序本身本质上只是程序代码,但因为QFtp是异步的,这使我疯狂。我需要测试多个ftp下载是否成功,但代码不阻塞,所以测试总是失败。到目前为止,最好的解决方案是创建一个链接的信号和插槽链接的ftp代码和过程部分。似乎有一个更好的方法。任何想法?

I'm an advanced beginner using Qt and I'm trying to write a console app that uses QFtp. The app itself is essentially just procedural code but because QFtp is asynchronous this is driving me crazy. I need to test that multiple ftp downloads are successful, but the code doesn't block so the test always fails. The best solution so far is to create a chain of signals and slots daisy chaining the ftp code and the procedural sections. It seems there has to be a better way. Any ideas?

推荐答案

您可以使用 QEventLoop 等待信号。只需将信号连接到 QEventLoop :: quit(),然后调用 QEventLoop :: exec() p>

You can use QEventLoop to wait for a signal. Just connnect the signal to QEventLoop::quit(), and then call QEventLoop::exec().

QFtp ftp;
QEventLoop eventLoop;
connect(&ftp, SIGNAL(commandFinished(int,bool)), &eventLoop, SLOT(quit()));
eventLoop.exec();

这篇关于在控制台应用程序中使用QFtp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆