Q(Plain)TextEdit: don't crash when using a style sheet
When using a style sheet, Q(Plain)TextEdit::isReadOnly() might get called during the initialization before d->control is properly initialized which lead to a crash. This amends 43ce457cbd093fc06d99b5ac833c789ef7c893d5. Fixes: QTBUG-121697 Fixes: QTBUG-121790 Task-number: QTBUG-1857 Change-Id: I15c357c9eef7f6559bcc2ad89033a3d8e7fcbfef Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit c6af5b9c12e1ea4cec007c5efe869636ce97a9d2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit e9b187a836974f05ba8f42eb72854a5effdc6c15) (cherry picked from commit ff1f12d5a0f57143e0e3c8d781bb3fdc884af7bc)
This commit is contained in:
parent
303586dd18
commit
b47ad83d7c
@ -2600,7 +2600,7 @@ void QPlainTextEdit::insertFromMimeData(const QMimeData *source)
|
|||||||
bool QPlainTextEdit::isReadOnly() const
|
bool QPlainTextEdit::isReadOnly() const
|
||||||
{
|
{
|
||||||
Q_D(const QPlainTextEdit);
|
Q_D(const QPlainTextEdit);
|
||||||
return !(d->control->textInteractionFlags() & Qt::TextEditable);
|
return !d->control || !(d->control->textInteractionFlags() & Qt::TextEditable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlainTextEdit::setReadOnly(bool ro)
|
void QPlainTextEdit::setReadOnly(bool ro)
|
||||||
|
@ -2213,7 +2213,7 @@ void QTextEdit::insertFromMimeData(const QMimeData *source)
|
|||||||
bool QTextEdit::isReadOnly() const
|
bool QTextEdit::isReadOnly() const
|
||||||
{
|
{
|
||||||
Q_D(const QTextEdit);
|
Q_D(const QTextEdit);
|
||||||
return !(d->control->textInteractionFlags() & Qt::TextEditable);
|
return !d->control || !(d->control->textInteractionFlags() & Qt::TextEditable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTextEdit::setReadOnly(bool ro)
|
void QTextEdit::setReadOnly(bool ro)
|
||||||
|
@ -133,6 +133,7 @@ private slots:
|
|||||||
void placeholderVisibility_data();
|
void placeholderVisibility_data();
|
||||||
void placeholderVisibility();
|
void placeholderVisibility();
|
||||||
void scrollBarSignals();
|
void scrollBarSignals();
|
||||||
|
void dontCrashWithCss();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createSelection();
|
void createSelection();
|
||||||
@ -1944,5 +1945,14 @@ void tst_QPlainTextEdit::scrollBarSignals()
|
|||||||
QTRY_COMPARE(spy.count(), 5);
|
QTRY_COMPARE(spy.count(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QPlainTextEdit::dontCrashWithCss()
|
||||||
|
{
|
||||||
|
qApp->setStyleSheet("QWidget { font: 10pt; }");
|
||||||
|
QPlainTextEdit edit;
|
||||||
|
edit.show();
|
||||||
|
qApp->setStyleSheet(QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QPlainTextEdit)
|
QTEST_MAIN(tst_QPlainTextEdit)
|
||||||
#include "tst_qplaintextedit.moc"
|
#include "tst_qplaintextedit.moc"
|
||||||
|
@ -198,6 +198,8 @@ private slots:
|
|||||||
void nextFormatAfterEnterPressed_data();
|
void nextFormatAfterEnterPressed_data();
|
||||||
void nextFormatAfterEnterPressed();
|
void nextFormatAfterEnterPressed();
|
||||||
|
|
||||||
|
void dontCrashWithCss();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createSelection();
|
void createSelection();
|
||||||
int blockCount() const;
|
int blockCount() const;
|
||||||
@ -3064,5 +3066,14 @@ void tst_QTextEdit::nextFormatAfterEnterPressed()
|
|||||||
QCOMPARE(prevBlockCursor.charFormat().property(it.key()), it.value());
|
QCOMPARE(prevBlockCursor.charFormat().property(it.key()), it.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTextEdit::dontCrashWithCss()
|
||||||
|
{
|
||||||
|
qApp->setStyleSheet("QWidget { font: 10pt; }");
|
||||||
|
QTextEdit edit;
|
||||||
|
edit.show();
|
||||||
|
qApp->setStyleSheet(QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QTextEdit)
|
QTEST_MAIN(tst_QTextEdit)
|
||||||
#include "tst_qtextedit.moc"
|
#include "tst_qtextedit.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user