mardi 5 mars 2019

Qt signal connection results in a segfault

This might be a bit vague, but I'm puzzled here.

I have a code like this:

auto dialog = new LayoutOptimizationDialog{*m_mainWindow, LayoutOptimizer{m_mediator->mindMapData()}};

connect(dialog, &LayoutOptimizationDialog::undoPointRequested, m_mediator.get(), &Mediator::saveUndoPoint);

if (dialog->exec() == QDialog::Accepted)
{
    m_mediator->zoomToFit();
}

emit actionTriggered(StateMachine::Action::LayoutOptimized);

The code just opens a modal dialog where the user can choose to optimize a layout, but it's irrelevant here what the dialog does.

The problem is that this signal connection alone causes a segfault in the dialog code. If I remove the signal connection everything works.

How is this possible? The signal is never triggered. There's no such code. It's just in the header file:

class LayoutOptimizationDialog : public QDialog {
    Q_OBJECT

public:

    //! Constructor.
    explicit LayoutOptimizationDialog(QWidget & parent, LayoutOptimizer && layoutOptimizer);

    int exec() override;

signals:

    void undoPointRequested();

Can someone please tell me how can the signal connection alone have such side effects in this case even in theory? :)

Aucun commentaire:

Enregistrer un commentaire