у меня есть Qdialogbox, и в этом qdialogbox у меня есть поток (с именем thread3), который выполняет функцию Print_Descendants_key(IUIAutomation* pUIAutomation, IUIAutomationElement* pParent, int indent)
в этом потоке3.
поэтому в моем Accepted событии (когда я нажимаю ОК в кнопочном поле) и closeEvent диалогового окна, я хочу выйти / завершить этот поток 3. Как я могу это сделать?
возможно что-то вроде этого ??
void KeyComd::closeEvent(QCloseEvent* event)
{
std::terminate();
thread3.terminate(); ??
}
void KeyComd::accepted()
{
std::terminate();
}
для справки вот мой код QDialog
#include "KeyComd.h"
#include "ui_KeyComd.h"
#include <QtCore>
#include <QtGui>
#include <vector>
#include<QDebug>
#include "ExecutionContext.h"
#include "XMLParser.h"
#include "Logger.h"
#include "BlockCommand.h"
#include "UIAElementUtils.h"
ExecutionContext exc;
QStringList refreshed_elements;
KeyComd::KeyComd(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
HRESULT hr = exc.init();
}
KeyComd::~KeyComd()
{
}
void KeyComd::on_showbutton_clicked()
{
ui.elements_listwidget->clear();
desktop_elements.clear();
std::thread thread3(&KeyComd::Print_step, this); // Here it calls a thread, because of this thread ,the execution of "Print_Descendants_key" function happens in a separate thread from main thread
thread3.detach();
}
void KeyComd::Print_step()
{
Print_Descendants_key(exc.pUIAutomation, nullptr, 0);
}
void KeyComd::Print_Descendants_key(IUIAutomation* pUIAutomation, IUIAutomationElement* pParent, int indent)
{
///Function which appends 1000 list-items in a QListWidget called "elements_listwidget" in my QDialog.
}