fixed bug caused by calling GUI out of main GUI thread

This commit is contained in:
csoler 2020-11-15 13:42:22 +01:00
parent f9bb886c27
commit aa16be6450

View file

@ -26,6 +26,7 @@
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
#include "hashingstatus.h" #include "hashingstatus.h"
#include "gui/common/ElidedLabel.h" #include "gui/common/ElidedLabel.h"
#include "util/qtthreadsutils.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
@ -54,13 +55,13 @@ HashingStatus::HashingStatus(QWidget *parent)
statusHashing->hide(); statusHashing->hide();
mEventHandlerId=0; mEventHandlerId=0;
rsEvents->registerEventsHandler( rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId, RsEventType::SHARED_DIRECTORIES );
[this](std::shared_ptr<const RsEvent> event) { handleEvent(event); },
mEventHandlerId, RsEventType::SHARED_DIRECTORIES );
} }
void HashingStatus::handleEvent(std::shared_ptr<const RsEvent> event) void HashingStatus::handleEvent(std::shared_ptr<const RsEvent> event)
{ {
// Warning: no GUI calls should happen here!
if(event->mType != RsEventType::SHARED_DIRECTORIES) if(event->mType != RsEventType::SHARED_DIRECTORIES)
return; return;
@ -85,7 +86,9 @@ void HashingStatus::handleEvent(std::shared_ptr<const RsEvent> event)
break; break;
} }
updateHashingInfo(info); // GUI calls should only happen in the GUI thread, which is achieved by postToObject().
RsQThreadUtils::postToObject( [this,info]() { updateHashingInfo(info); }, this);
} }
HashingStatus::~HashingStatus() HashingStatus::~HashingStatus()