From 6a60dd9a73cf336a67fdce4f8e067953c765fad9 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 9 Nov 2024 13:17:26 +0100 Subject: Fix handling of QCompleter in SmInputDialog setCompleter() assumed that QLineEdit always had a valid completer and schedule it for later deletion. This caused random crashes when there was no deleter. So make sure that mLE always a valid deleter and set the model instead of a new completer. --- sminputdialog.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sminputdialog.cpp') diff --git a/sminputdialog.cpp b/sminputdialog.cpp index f078141..ecd43c2 100644 --- a/sminputdialog.cpp +++ b/sminputdialog.cpp @@ -3,12 +3,15 @@ #include #include #include +#include #include "sminputdialog.h" SmInputDialog::SmInputDialog(const QString &label, QWidget *parent) : QDialog(parent){ QLabel *thisL = new QLabel(label); mLE = new QLineEdit; + mCompleter = new QCompleter(this); + mLE->setCompleter(mCompleter); QPushButton *cancelPB = new QPushButton(tr("Cancel")); connect(cancelPB, &QPushButton::clicked, this, &SmInputDialog::reject); QPushButton *acceptPB = new QPushButton(tr("OK")); @@ -30,7 +33,6 @@ void SmInputDialog::setText(QString &text){ mLE->setText(text); } -void SmInputDialog::setCompleter(QCompleter *completer){ - mLE->completer()->deleteLater(); - mLE->setCompleter(completer); +void SmInputDialog::setCompleterModel(const QStringList &model){ + mCompleter->setModel(new QStringListModel(model)); } -- cgit v1.2.3-70-g09d2