[Qt-creator] R.I.P. for QPlainTextEdit in Qr Creator 17?
Henry Skoglund
henry at tungware.se
Tue Jun 24 17:04:48 CEST 2025
On 2025-06-24 16:36, Robert Löhning via Qt-creator wrote:
> Am 21.06.25 um 16:17 schrieb Henry Skoglund:
>> On 2025-06-19 22:51, apoenitz wrote:
>>> Hi.
>>>
>>> On Wed, Jun 18, 2025 at 06:05:08PM +0200, Henry Skoglund wrote:
>>>> Hi, just updated to Qt Creator 17 and it looks good, however when
>>>> rebuilding
>>>> my Qt Creator plugin I got stuck for a bit with this failing:
>>>>
>>>> auto pe =
>>>> qobject_cast<QPlainTextEdit*>(EditorManager::currentEditor()->widget());
>>>>
>>>>
>>>> For almost 15 years that statement served me well and it allowed
>>>> for example
>>>> setting a fatter cursor at Qt Creator start (useful on 4K screens) but
>>>> today, it returns a nullptr :-(
>>>>
>>>>
>>>> Instead, the new incantation for Qt Creator 17 (and onwards?) seems
>>>> to be:
>>>>
>>>> auto pe =
>>>> qobject_cast<Utils::PlainTextEdit*>(EditorManager::currentEditor()-
>>>> >widget());
>>>>
>>>> After that fix, it's smooth sailing (Utils::PlainTextEdit behaves 100%
>>>> compatible with QPlainTextEdit).
>>>>
>>>> But if there was a bit of documentation of this new class in the
>>>> Utils::
>>>> Namespace I would be even more happy!
>>> Sorry to hear that this bit you.
>>>
>>> I guess nobody expected that some plugin out there had a hard
>>> dependency
>>> on Editor::widget() being in fact a QPlainTextEdit for text editors.
>>>
>>> The fact that Utils::PlainTextEdit behaves like QPlainTextEdit is not
>>> quite an accident, the idea is add a few features and try to upstream
>>> it to Qt proper again. For this to happen it has to stay compatible.
>>>
>>> In case this upstreaming will be successful there's a good chance that
>>> Utils::PlainTextEdit will vanish again. But then there'll hopefully
>>> be a more communication.
>>>
>> Thanks for answering, it's all working fine now with the new
>> Utils::PlainTextEdit.
>>
>> Perhaps I'm doing it wrong, i.e. I shouldn't take a hard dependency
>> on the built-in editor being of a certain class.
>>
>> Say I were to write a new plugin to Qt Creator having only one
>> command, like F5 in Notepad in Windows: inserting the current date
>> and time where the text cursor is.
>>
>> What would the best approach be? (Utils::MacroExpander could probably
>> be good enough for inserting the date but what about the time.)
>>
>
> Hi Henry,
>
> does it have to be exactly a plugin? In "Tools" -> "External" ->
> "Configure..." you can easily set up something which inserts the
> output of the system's "date" command (and also "time" on Windows).
>
> Cheers,
> Robert
>
Hi, well yes for inserting date/time an external tool surely would suffice,
but I was thinking more how you would write a new plugin today with
similar functions lika my "real" one:
e.g. having a macro for inserting "QString("")" and moving the text
cursor to the left 2 times (to begin typing inside the quotes)
or a macro for inserting comments, either # or // depending on what file
type you are editing (c++ or CMake)
So in general, requiring a bit more intelligence, like a plugin :-)
More information about the Qt-creator
mailing list