Ich habe versucht, Signal finished()
aus meiner Klasse zu emittieren. Aber wenn ich das Signal an meinen Steckplatz anschließe, hat es nichts bewirkt.Emittiertes Signal wird nicht erkannt
Der Name meiner Klasse ist blend_install
, ich habe es als blendinstaller
deklariert und habe versucht, das mit dem QEventLoop zu verbinden.
....
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();
....
Die download()
Funktion:
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!");
So, TL; DR jeweils Fehler Handhabung aus der Funktion zurück, sondern auch finished()
und am Ende der Funktion emittieren (vorausgesetzt, kein Fehler vorhanden ist) Es wird finished()
emittieren.
Die Schleife wird nicht beendet.
Irgendeine Idee?
Es fein sieht. Können Sie Ihre 'download()' Implementierung posten? Ich kann mir nur vorstellen, dass Ihre 'download()' Methode das 'finished()' Signal zu früh abgibt. Besser gesagt: Es sollte überhaupt nicht aufgerufen werden. Normalerweise würde irgendeine Art von privatem Slot 'onDownloadComplete()' das 'finished() 'Signal ausgeben. – mfreiholz
@mfreiholz Ich habe das hochgeladen, und ich werde Ihren Vorschlag versuchen ... –
Es ist immer print, dass "es fertig ist zu installieren!" Nachricht, sendet aber immer noch nicht das 'finished()' Signal. –