[Development] Go's "defer" statement for C++/Qt
volker.hilsheimer at qt.io
Thu Mar 7 18:52:16 CET 2019
deferred signal emission (or rather, deferred slot invocation) is a different topic. Wouldn't work well in my example, for the lack of an event loop. And object lifetime management would either way be a mess.
Suggest you check the link to the explanation of go that I included 🙂
From: Alexander Akulich <akulichalexander at gmail.com>
Sent: Thursday, March 7, 2019 6:24 PM
To: Volker Hilsheimer
Cc: Qt development mailing list
Subject: Re: [Development] Go's "defer" statement for C++/Qt
I have no idea about Go, but deferred signal emission is somewhat
useful in async programming (at least in my practice). In that case,
there is a need to 'defer' execution to continue after the control is
returned (usually in EventLoop via QMetaObject::invokeMethod(...,
Qt::QueuedConnection). A cleaner approach would be appreciated.
On Thu, Mar 7, 2019 at 8:02 PM Volker Hilsheimer
<volker.hilsheimer at qt.io> wrote:
> In what little development I’ve done in golang, I appreciated the “defer” statement as a means to write cleaner code. Basically, defer schedules a statement for execution when the stack unwinds.
> We have several specialized helper classes in Qt for similar purposes, f.ex QMutexLocker and friends, or the internal QBoolBlocker . Seeing the various specialized classes we have, I thought that something generic in Qt could be useful to have (although our specialised classes provide some additional convenience and/or logic).
> So, I pushed a few lines code to
> Would like to hear what you think.
> Perhaps someone can find ways to make this more elegant without introducing tons of preprocessor/macro shenanigans, or perhaps even without depending on C++17's implicit template argument deduction (without enabling C++17 in the config this doesn't build for me, even though I don’t use auto in the template paramter list).
>  which was requested to be made public in https://bugreports.qt.io/browse/QTBUG-38575
> Development mailing list
> Development at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Development