KTextEditor::ModificationInterface in connect

Daan De Meyer daan.j.demeyer at gmail.com
Tue Aug 20 08:28:01 BST 2019


connect requires `ModificationInterface` to contain a `Q_OBJECT` call
when using the new signal/slot syntax (which it doesn't contain).
Otherwise, we need to cast to the actual private implementation class
to use the slot (assuming that class does contain `Q_OBJECT`) but from
what I can understand from KTextEditor's design this might not be
possible or desirable.

Putting `Q_OBJECT` in all the interface classes might work but then we
get into the issue again that we'd have to rely on the latest version
of frameworks to be able to rely on that being there.

Regards,

Daan

On Tue, 20 Aug 2019 at 09:04, Christoph Cullmann <christoph at cullmann.io> wrote:
>
> On 2019-08-19 22:17, Daan De Meyer wrote:
> > Hi,
> >
> > I was trying to refactor some of the old Qt signal/slot usage in Kate
> > to the new syntax. However, when trying to refactor code using
> > `modifiedOnDisk` from `KTextEditor::ModificationInterface`, I'm
> > getting compilation errors that I'm not sure how to fix.
> >
> > Before:
> >
> > connect(doc, SIGNAL(modifiedOnDisk(KTextEditor::Document *, bool,
> > KTextEditor::ModificationInterface::ModifiedOnDiskReason)),
> > this, SLOT(documentModifiedOnDisc(KTextEditor::Document *, bool,
> > KTextEditor::ModificationInterface::ModifiedOnDiskReason)));
> >
> > After:
> >
> > auto interface = qobject_cast<KTextEditor::ModificationInterface
> > *>(doc);
> > if (interface) {
> > connect(interface, &KTextEditor::ModificationInterface::modifiedOnDisk,
> > this,
> > &KateFileTreeModel::documentModifiedOnDisc);
> > }
> >
> > Compilation error highlights:
> >
> > /usr/include/qt/QtCore/qobjectdefs.h: In instantiation of ‘struct
> > QtPrivate::HasQ_OBJECT_Macro<KTextEditor::ModificationInterface>’:
> >
> > /usr/include/qt/QtCore/qobject.h:238:9: error: static assertion
> > failed: No Q_OBJECT in the class with the signal
> >   238 |
> > Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<typename
> > SignalType::Object>::Value,
> >       |         ^~~~~~~~~~~~~~~~~
> >
> > Any ideas on how to use KTextEditor::ModificationInterface with the
> > modern Qt signal/slot syntax?
>
> The modification interface is just an interface.
> Perhaps that creates this error, thought not sure how to fix that
> properly.
>
> Greetings
> Christoph
>
> >
> > Regards,
> >
> > Daan
>
> --
> Ignorance is bliss...
> https://cullmann.io | https://kate-editor.org


More information about the KWrite-Devel mailing list