File tree Expand file tree Collapse file tree 2 files changed +31
-8
lines changed
Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 2929#endif
3030
3131#include " ThumbnailSource.h"
32+
33+ #include < QThread>
34+
3235#include " FileUtilities.h"
3336
3437#include < App/Application.h>
@@ -45,6 +48,14 @@ ThumbnailSource::ThumbnailSource(QString file)
4548 : _file(std::move(file))
4649{}
4750
51+ ThumbnailSource::~ThumbnailSource ()
52+ {
53+ if (_process && _process->state () == QProcess::Running) {
54+ _process->kill ();
55+ _process->waitForFinished ();
56+ }
57+ }
58+
4859ThumbnailSourceSignals* ThumbnailSource::signals ()
4960{
5061 return &_signals;
@@ -64,10 +75,18 @@ void ThumbnailSource::run()
6475 QStringList args (_f3dBaseArgs);
6576 args << QLatin1String (" --output=" ) + thumbnailPath << _file;
6677
67- QProcess process;
68- process.start (f3d, args);
69- process.waitForFinished ();
70- if (process.exitCode () != 0 ) {
78+ _process = std::make_unique<QProcess>();
79+ _process->start (f3d, args);
80+
81+ // Since this is running on a non-GUI thread, poll for an interruption request while running
82+ // so that external code can kill the process if necessary.
83+ constexpr int checkEveryMs {50 };
84+ while (_process->waitForFinished (checkEveryMs)) {
85+ if (QThread::currentThread ()->isInterruptionRequested ()) {
86+ _process->kill ();
87+ }
88+ }
89+ if (_process->exitCode () != 0 ) {
7190 return ;
7291 }
7392 }
Original file line number Diff line number Diff line change 2121 * *
2222 ***************************************************************************/
2323
24- #ifndef FREECAD_THUMBNAILSOURCE_H
25- #define FREECAD_THUMBNAILSOURCE_H
24+ #ifndef FREECAD_THUMBNAIL_SOURCE_H
25+ #define FREECAD_THUMBNAIL_SOURCE_H
2626
27- #include < QByteArray>
2827#include < QRunnable>
2928#include < QString>
3029#include < QObject>
3130#include < QMutex>
3231#include < QStringList>
3332
33+ class QProcess ;
34+
3435namespace Start
3536{
3637
@@ -47,6 +48,7 @@ class ThumbnailSource: public QRunnable
4748{
4849public:
4950 explicit ThumbnailSource (QString file);
51+ ~ThumbnailSource () override ;
5052
5153 void run () override ;
5254
@@ -57,6 +59,8 @@ class ThumbnailSource: public QRunnable
5759
5860 QString _file;
5961 ThumbnailSourceSignals _signals;
62+ std::unique_ptr<QProcess> _process;
63+
6064 static bool _f3dInitialized;
6165 static int _f3dMajor;
6266 static int _f3dMinor;
@@ -66,4 +70,4 @@ class ThumbnailSource: public QRunnable
6670
6771} // namespace Start
6872
69- #endif // FREECAD_THUMBNAILSOURCE_H
73+ #endif // FREECAD_THUMBNAIL_SOURCE_H
You can’t perform that action at this time.
0 commit comments