[Qt-creator] TextEditor plugin: how to set QTextDocument in BaseTextEditorWidget?

Thorbjørn Lindeijer thorbjorn at lindeijer.nl
Wed May 28 21:25:59 CEST 2014


Hey Vitali,

What you may have failed to do is to look at the lines on which the 
SOFT_ASSERT is failing. They look like this:

>     BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout());
>     QTC_ASSERT(documentLayout, return);

So what you need to do is for your text document is to make sure it has 
this custom layout subclass set on it as well. This code is found in the 
BaseTextDocument constructor:

>     BaseTextDocumentLayout *documentLayout = new BaseTextDocumentLayout(d->m_document);
>     d->m_document->setDocumentLayout(documentLayout);

I hope that may help you.

Regards,
Bjørn

On 28.05.2014 17:12, Vitali Baumtrok wrote:
> Hello,
>
> is there a possibility to set the QTextDocument in BaseTextEditorWidget
> of the TextEditor plugin?
>
> I need to integrate a class which derives from QTextDocument with the
> BaseTextEditorWidget.
>
> Qt Creator 3.1.0 is used.
>
>
> Here is the problem in TextEditor plugin source code:
>
> BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
>       m_fontSettingsNeedsApply(false),
>       m_document(new QTextDocument(q)),  // <=== QTextDocument
> instantiation !
>       m_highlighter(0),
>       m_indenter(new Indenter),
>       m_fileIsReadOnly(false),
>       m_autoSaveRevision(-1)
> {
> }
>
> BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
> {
>       connect(d->m_document, SIGNAL(modificationChanged(bool)), d,
> SLOT(onModificationChanged(bool)));
>       connect(d->m_document, SIGNAL(modificationChanged(bool)), this,
> SIGNAL(changed()));
>       connect(d->m_document, SIGNAL(contentsChanged()), this,
> SIGNAL(contentsChanged()));
>       ...
> }
>
>
> example code:
> BaseTextEditorWidget *btew = new BaseTextEditorWidget;
> btew->setDocument(new QTextDocument(btew));
>
> result:
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 585
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 2800
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 2800
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 2800
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 2800
> SOFT ASSERT: "documentLayout" in file
> /home/qt-creator-3.1.0/src/plugins/texteditor/basetexteditor.cpp, line 2800
> and so on....
>
> The editor is empty, i.e. shows no text.
>
>
> It seems that it is impossible to do what I want. Did I miss something
> or is there a workaround?



More information about the Qt-creator mailing list