我試圖從我的班級發出信號finished()
。但是當我將信號連接到我的插槽時,它什麼也沒有做。未檢測到發射信號
我的班級的名字是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()'方法過早地發出'finished()'信號。更好地說:它不應該從它被調用。通常某種專用插槽'onDownloadComplete()'會發出'finished()'信號。 – mfreiholz
@mfreiholz我已經上傳了,我會嘗試你的建議... –
它總是打印「它已經完成安裝!」消息,但仍不會發出'finished()'信號。 –