How to access the Accepted and Close Event of QDialogbox
-
i have a Qdialogbox and in this qdialogbox i have a thread(named thread3) which executes
Print_Descendants_key(IUIAutomation* pUIAutomation, IUIAutomationElement* pParent, int indent)
so in my Accepted event(when i click okay in buttonbox) and closeEvent of dialog box, i want to quit/terminate this thread3. How can i do that ?
probably something like this ??
void KeyComd::closeEvent(QCloseEvent* event) { std::terminate(); thread3.terminate(); ?? } void KeyComd::accepted() { std::terminate(); }
for reference here is my QDialog code
#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. }
-
@learnist said in How to access the Accepted and Close Event of QDialogbox:
std::thread thread3(&KeyComd::Print_step, this);
If you want to access your thread outside of KeyComd::on_showbutton_clicked() then make thread3 member variable first...
-
@jsulm said in How to access the Accepted and Close Event of QDialogbox:
If you want to access your thread outside of KeyComd::on_showbutton_clicked() then make thread3 member variable first...
How can i do that ?? , where do i declare it to make it a member variable ? in my .h or . cpp file ??
-
Hi,
In your class declaration.
Note that this is basic C++. If you do not know that, I highly encourage you to first improve your C++ knowledge before going further.