Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to access the Accepted and Close Event of QDialogbox
Forum Updated to NodeBB v4.3 + New Features

How to access the Accepted and Close Event of QDialogbox

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qdialogthreadmultithreading
4 Posts 3 Posters 870 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    learnist
    wrote on last edited by
    #1

    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.
    }
    
    jsulmJ 1 Reply Last reply
    0
    • L learnist

      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.
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      1
      • jsulmJ jsulm

        @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...

        L Offline
        L Offline
        learnist
        wrote on last edited by
        #3

        @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 ??

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved