<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi Julierme,</p>
    <p>I think Your problem is, that You try to create a new application
      with "app = QApplication(sys.argv)" inside a running QGis, which
      already is a running Qt-application.</p>
    <p>Simplified code should perform without crash:</p>
    <p>import sys<br>
      from PyQt5.QtCore import (QSize,Qt)<br>
      from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton,
      QMainWindow)</p>
    <p>class MainWindow(QMainWindow):<br>
          def _init_(self):<br>
              super()._init_()<br>
              self.setWindowTitle("My App")<br>
              button = QPushButton("Press Me!")<br>
      <br>
             <br>
              self.setCentralWidget(button)<br>
              self.setFixedSize(QSize(400,300))<br>
      <br>
      window = MainWindow()<br>
      window.show() <br>
    </p>
    <p><br>
    </p>
    <p>hth</p>
    <p>Ludwig<br>
    </p>
    <div class="moz-cite-prefix">Am 16.08.23 um 19:15 schrieb 1520 gis
      via QGIS-User:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKTKyJKD5n-8Kk4v7y0ynOf-Q3z0Xs-sQhQW+Pxt2HnveNBmbg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi all,
        <div><br>
        </div>
        <div>I wrote the PyQt script below and I am running it
          through QGIS3. When I run it for the first time after opening
          it in QGIS3, the application's window pops up smoothly.
          However, when I close the window and run the script, QGIS3
          readily quits.  That may be something related to the event
          loop, but I'm unsure and don't know how to stop the QGIS3
          shutdown for the subsequent runs.  Any hint on how to fix this
          issue will be very appreciated. </div>
        <div><br>
        </div>
        <div>import sys<br>
          from PyQt5.QtCore import (QSize,<br>
                                    Qt)<br>
          from PyQt5.QtWidgets import (QApplication,<br>
                                        QWidget,<br>
                                        QPushButton,<br>
                                        QMainWindow)<br>
        </div>
        <div>class MainWindow(QMainWindow):<br>
              def _init_(self):<br>
                  super()._init_()<br>
                  self.setWindowTitle("My App")<br>
                  button = QPushButton("Press Me!")<br>
          <br>
                 <br>
                  self.setCentralWidget(button)<br>
                  self.setFixedSize(QSize(400,300))<br clear="all">
          <div>app = QApplication(sys.argv)<br>
            window = MainWindow()<br>
            window.show() <br>
            app.exec()<br>
          </div>
          <span class="gmail_signature_prefix">-- </span><br>
          <div dir="ltr" class="gmail_signature"
            data-smartmail="gmail_signature">
            <div dir="ltr">
              <div><font face="verdana, sans-serif">##########################################</font></div>
              <font size="4" face="verdana, sans-serif"><b><font
                    color="#20124d">Julierme G Pinheiro</font></b><br>
                <b><font color="#660000">SDI Expert & Geoprocessing
                    Specialist</font></b></font>
              <div><font size="4" face="verdana, sans-serif"><font
                    color="#351c75">Phone:</font> <font color="#444444">+55
                    61 99994-3569</font></font></div>
              <div><font size="4" face="verdana, sans-serif"><font
                    color="#351c75">Website:</font> <a
href="https://www.udemy.com/course/qgis-server-para-iniciantes-instalacao-e-configuracao/"
                    target="_blank" moz-do-not-send="true">GIS</a></font></div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-User mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-User@lists.osgeo.org">QGIS-User@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
    </blockquote>
  </body>
</html>