扫描取消从界面线程分离,单独创建线程,防止界面卡死

This commit is contained in:
yangjiaxuan 2023-11-09 14:57:51 +08:00
parent e018ad18f8
commit 230370acd5
2 changed files with 18 additions and 1 deletions

View File

@ -15,6 +15,7 @@ Dialog_progress_ui::Dialog_progress_ui(class Manager *mgr, std::function<void (u
, m_imageRecivedCount(0) , m_imageRecivedCount(0)
, m_isScanning(false) , m_isScanning(false)
, m_thread(nullptr) , m_thread(nullptr)
, m_thread_cancelScan(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -49,6 +50,10 @@ Dialog_progress_ui::~Dialog_progress_ui()
{ {
HGBase_CloseThread(m_thread); HGBase_CloseThread(m_thread);
m_thread = nullptr; m_thread = nullptr;
HGBase_CloseThread(m_thread_cancelScan);
m_thread_cancelScan = nullptr;
m_mgr->m_progressUi = nullptr; m_mgr->m_progressUi = nullptr;
delete ui; delete ui;
@ -73,7 +78,10 @@ void Dialog_progress_ui::closeEvent(QCloseEvent* e)
void Dialog_progress_ui::on_pbtn_cancelScan_clicked() void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
{ {
if (!quit_) if (!quit_)
m_callback(UI_RESULT_CLOSE_CANCEL); {
HGBase_OpenThread(CancelScanThreadFunc, this, &m_thread_cancelScan);
}
ui->pbtn_cancelScan->setVisible(false); ui->pbtn_cancelScan->setVisible(false);
ui->label->setText(tr("stop scanning")); ui->label->setText(tr("stop scanning"));
} }
@ -137,6 +145,13 @@ void HGAPI Dialog_progress_ui::ThreadFunc(HGThread thread, HGPointer param)
p->m_callback(UI_RESULT_CLOSE_NORMAL); p->m_callback(UI_RESULT_CLOSE_NORMAL);
} }
void HGAPI Dialog_progress_ui::CancelScanThreadFunc(HGThread thread, HGPointer param)
{
Dialog_progress_ui* p = (Dialog_progress_ui*)param;
if (p->m_callback)
p->m_callback(UI_RESULT_CLOSE_CANCEL);
}
void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag) void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag)
{ {
Dialog_progress_ui *p = (Dialog_progress_ui *)g_manager->m_progressUi; Dialog_progress_ui *p = (Dialog_progress_ui *)g_manager->m_progressUi;

View File

@ -39,6 +39,7 @@ private slots:
public: public:
static void HGAPI ThreadFunc(HGThread thread, HGPointer param); static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
static void HGAPI CancelScanThreadFunc(HGThread thread, HGPointer param);
static void FuncNotify(int event, void *msg, int flag); static void FuncNotify(int event, void *msg, int flag);
void clear_callback(void) void clear_callback(void)
{ {
@ -56,6 +57,7 @@ private:
QTimer *m_timer; QTimer *m_timer;
bool m_isScanning; bool m_isScanning;
HGThread m_thread; HGThread m_thread;
HGThread m_thread_cancelScan;
}; };
#endif // DIALOG_PROGRESS_UI_H #endif // DIALOG_PROGRESS_UI_H