扫描取消从界面线程分离,单独创建线程,防止界面卡死
This commit is contained in:
parent
e018ad18f8
commit
230370acd5
|
@ -15,6 +15,7 @@ Dialog_progress_ui::Dialog_progress_ui(class Manager *mgr, std::function<void (u
|
|||
, m_imageRecivedCount(0)
|
||||
, m_isScanning(false)
|
||||
, m_thread(nullptr)
|
||||
, m_thread_cancelScan(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -49,6 +50,10 @@ Dialog_progress_ui::~Dialog_progress_ui()
|
|||
{
|
||||
HGBase_CloseThread(m_thread);
|
||||
m_thread = nullptr;
|
||||
|
||||
HGBase_CloseThread(m_thread_cancelScan);
|
||||
m_thread_cancelScan = nullptr;
|
||||
|
||||
m_mgr->m_progressUi = nullptr;
|
||||
|
||||
delete ui;
|
||||
|
@ -73,7 +78,10 @@ void Dialog_progress_ui::closeEvent(QCloseEvent* e)
|
|||
void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
|
||||
{
|
||||
if (!quit_)
|
||||
m_callback(UI_RESULT_CLOSE_CANCEL);
|
||||
{
|
||||
HGBase_OpenThread(CancelScanThreadFunc, this, &m_thread_cancelScan);
|
||||
}
|
||||
|
||||
ui->pbtn_cancelScan->setVisible(false);
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Dialog_progress_ui *p = (Dialog_progress_ui *)g_manager->m_progressUi;
|
||||
|
|
|
@ -39,6 +39,7 @@ private slots:
|
|||
|
||||
public:
|
||||
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);
|
||||
void clear_callback(void)
|
||||
{
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
QTimer *m_timer;
|
||||
bool m_isScanning;
|
||||
HGThread m_thread;
|
||||
HGThread m_thread_cancelScan;
|
||||
};
|
||||
|
||||
#endif // DIALOG_PROGRESS_UI_H
|
||||
|
|
Loading…
Reference in New Issue