PyQt5 - Show QDialog from a different class
<p>My app consist of a <code>QMainWindow</code> with a <code>QToolBar</code>. My purpose is to click on a <code>QToolBar</code> element and open in a separate window (<code>QDialog</code>) a calendar.</p>

<p>I want to create in a separate class a <code>QDialog</code> and call it to be shown from the <code>QMainWindow</code>.</p>

<p>This is my <code>QDialog</code>, just a Calendar:</p>

<pre><code>class CalendarDialog(QDialog):

    def __init__(self):
        super().__init__(self)
        cal = QCalendarWidget(self)            
</code></pre>

<p>Now from a <code>QMainWindow</code> I would like to show the calendar after an action trigger like next:</p>

<pre><code>class Example(QMainWindow):
    ...
    calendarAction.triggered.connect(self.openCalendar)
    ...
    def openCalendar(self):
        self.calendarWidget = CalendarDialog(self)
        self.calendarWidget.show()
</code></pre>

<p>It isn't working. After the event that calls <code>openCalendar</code> the app is closed without printing any output error. I have put some prints to debug and <code>CalendarDialog.__init__(self)</code> isn't even called.</p>

<p>The code regarding to <code>QToolBar</code> is as follow:</p>

<pre><code>openCalendarAction = QAction(QIcon(IMG_CALENDAR), "", self)
openCalendarAction.triggered.connect(self.openCalendar)
self.toolbar.addAction(openCalendarAction)
</code></pre>