- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图从我的类(class)发出信号 finished()
。但是当我将信号连接到我的插槽时,它什么也没做。
我的类(class)名称是 blend_install
,我将其声明为 blendinstaller
并尝试将其连接到 QEventLoop。
....
QEventLoop ac;
connect(&blendinstaller, SIGNAL(finished()), &ac, SLOT(quit()));
blendinstaller.show_progress();
blendinstaller.download(); // this will execute everything and in the end emit finished()
ac.exec();
....
download()
函数:
current_prog = BLEND_INSTALL_NONE;
emit progress_changed(current_prog);
manager = new QNetworkAccessManager;
file_handler = new QFile(downloadTo);
file_handler->open(QFile::WriteOnly);
.... handle error .... // each of this (error handling) will emit finished() signal and return;
.... // each of this will represent the process of reporting event changes (for logging), emit a SIGNAL()
QNetworkRequest request;
request.setUrl(QUrl(downloadFrom));
reply = manager->get(request);
event = new QEventLoop;
connect(reply,SIGNAL(finished()),event,SLOT(quit()));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(downloadError(QNetworkReply::NetworkError)));
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgressL(qint64,qint64)));
event->exec();
.... handle error ....
.... write reply.readAll() to file ....
....
// these are instruction for a custom QProcess instance
proc.setProgram(extractWith);
proc.setArguments(ar);
proc.setWorkingDirectory(downloadIn);
event = new QEventLoop;
connect(&proc,SIGNAL(finished(int)),event,SLOT(quit()));
connect(&proc,SIGNAL(error(QProcess::ProcessError)),this,SLOT(extractError(QProcess::ProcessError)));
connect(&proc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(extractFinished(int,QProcess::ExitStatus)));
proc.start();
proc.open_console();
event->exec();
.... handle error ....
....
.... attempt to find output of QProcess (extract an archive) ....
.... handle error, output of QProcess not found ....
....
emit installed(installOn);
emit finished(); // the SIGNAL I want to get.
qDebug("It's finished installing!");
因此,TL;DR 每个错误处理 都会从函数返回,但也会发出 finished()
并在函数结束时(假设没有错误)它将发出 finished()
。
它不会退出循环。
有什么想法吗?
最佳答案
download()
方法的问题在于,它已经是一个同步方法。你不需要这个事件循环。您已经在 download()
方法中的事件循环中完成了所有操作。
旁注:而且您似乎有一些内存泄漏,因为您在没有父级的情况下创建 QEventLoop 并且从不删除它。
更新#1:您的 finished()
事件未被外部 QEventLoop (ac
) 处理,因为 finished()
信号甚至在 QEventLoop 之前发出开始使用 exec()
处理事件。作为一个丑陋的解决方法,您可以在 exec()
之后使用排队的 QMetaObject::invokeMethod()
(Qt::QueuedConnection) 调用 download()
打电话(但我不推荐)。
更新#2这是一个小例子,当然还不完美:P
class BlendDownloader
{
Q_OBJECT
public:
BlenDownloader() :
_file(NULL)
{
}
void download()
{
_file = new QFile("C:/myfile.blubb");
QNetworkRequest req("your url here");
QNetworkReply* reply = _mgr.get(req);
QObject::connect(reply, SIGNAL(finished()), this, SLOT(onDownloadFinished()));
// TODO: Also handle error callback here
}
private slots:
void onDownloadFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
reply->deleteLater();
// Write response data to file.
// Note: You might get problems with big files,
// since this buffers the entire response of QNetworkReply
// in internal buffer. It's better to use the "readyRead()"
// signal and write incrementally.
_file->write(reply->readAll());
// Do your parsing stuff now and emit "finished()" at the end.
// ... parsing, validation here ...
// Clean up
_file->close();
delete _file;
_file = NULL;
emit finished();
}
private:
QNetworkManager _mgr;
QFile* _file;
};
关于c++ - 未检测到发射信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36396730/
我正在尝试使用 DynamicMethod 并尝试使用 IL 来创建一些对象。我想创建以下非常基本的对象: new Queue(new List{100}); 我已经使用 ILDASM 查看生成此代码
这是我stackoverflow的第一个问题!我有一个显示 mpl 图 Canvas 的 PyQT gui。我已将主轴周围的边距设置为 0,因此绘图将完全填满图形 Canvas 和包含它的小部件。问题
我的环境是 Windows 7,安装了 scala 2.11.4(运行良好),Java 1.8 我已经尝试过 spark-1.2.0-bin-hadoop2.4 和 spark-1.2.1-bin-h
对于我的生活,我无法弄清楚为什么我不能发送或捕获一些数据。 toggleNavigation() 触发,但我不确定 .emit() 是否真的在工作。 最终我想折叠和展开导航,但现在我只想了解如何将数据
我试图在 VUE 3 中传递一个 emit prop,每次传递它时我仍然得到 false,并且 prop 无法切换。 Accordion .vue
我有一个 View 模型,它采用初始 ViewState对象并具有可公开访问的 state可以收集的变量。 class MyViewModel(initialState: ViewState) : V
现在在玩 RxJava,偶然发现了以下问题: 我有 2 个不同的流: 带有项目的流 Stream(只有 1 个项目),它发出第一个流的转换信息。 所以基本上我有项目流,我希望所有这些项目与第二个流中的
我有一个 API 登录服务,它使用 http 服务来执行登录逻辑(LoginApiService、login-api.service.ts): login(data: LoginCredentials
我们有微服务架构,我们通过网络进行服务间调用。我们在顶层服务中使用 RxJava,这会导致向底层服务创建大量并行请求。因此,我收到“没有到主机的路由错误”或“连接错误”。为此,我想减慢 RxJava
Vue.component('rating-edit', { template:` {{rating.remark}} Sav
我最近购买了 Dream Cheeky Thunder 导弹发射器,我希望通过我的树莓派来控制它。 使用来自报复的代码(https://raw.githubusercontent.com/codeda
我制作了这段代码来记录发送到我的机器人的 DM: client.on('messageCreate', async message => { if (message.author.bot) r
我需要从服务器代码、路由器/ Controller 上的任何位置发出来自服务器的套接字。我检查了一些线程和谷歌,但没有按预期工作。 app.js var app = require('express'
我是一名优秀的程序员,十分优秀!