misje / once Goto Github PK
View Code? Open in Web Editor NEWConnect a Qt slot/functor/signal and disconnect it immediately after execution.
License: MIT License
Connect a Qt slot/functor/signal and disconnect it immediately after execution.
License: MIT License
In order to easily convey the purpose of once a few good use cases should be presented in the README. Example test code should implement them. Personally I have a hard time finding good examples that are not in proprietary code, so help is appreciated!
Have you considered submitting this to Qt codereview? It would be very nice to have this officially in Qt.
Qt 6 will require at least C++11 (maybe even higher), so this implementation should be good to go.
Related Qt bug: https://bugreports.qt.io/browse/QTBUG-44219
Hi! First of all thanks for your small helper. I was also surprised that this functionality has still not included in QT.
The problem is that the member AutoDisconnecter::func is treated as a reference and therefore it saves a reference to the functor object which is not saved elsewhere.
No idea why. You use "Func &&func" so Func should be deduced to the type itself.
It can be easily verified by static_assert( !std::is_reference< decltype( func ) >::value , ""), which won't compile.
The solution can be replacing the member with
std::remove_reference_t< Func > func;
Plus you need to remove const from operator () and call() as they call not-const callable of its member.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.