title: QT: How to close multiple windows of the same widget?
body: <p>I'm a beginner in programming in C++/Qt.
  I created a widget called wexample in Qt. When displayed, there is an button event that will open another window of the same widget wexample, and so on. My question is how to close all the windows of that widget?</p>
  
  <p>I open my first widget as follows:</p>
  
  <blockquote>
    <p>wexample *w = new wexample;<br>
    w-> show();</p>
  </blockquote>
  
  <p>Inside the widget, I also have these events:</p>
  
  <blockquote>
    <p>void wexample::on_pushButton1_clicked()<br>
    {<br>
      wexample *w = new wexample;<br>
      w -> show();<br>
    }<br>
    void wexample::on_pushButton2_clicked()<br>
    {<br>
      QWidget::close();<br>
    }</p>
  </blockquote>
  
  <p>So when button 1 is pressed, it will open a new window and so on. When button 2 is pressed, it will close the window where the button is. Is there a way to close all of the windows from that widget all at once? Or even better, is there a way to close specific windows (for example, all the windows after the 3rd one)?</p>
  
  <p>I have tried using signal and slot but I can't connect them since they are all of the same name. I would have to declare all of the widgets beforehand for it to work but I cannot know how many of them the user will need.</p>
  
  <p>I'm sorry if my question isn't clear. I am really a beginner and have been searching for a while but couldn't find an answer. Maybe the structure as a whole doesn't make sense. Please help. Thanks.</p>