QtUtils
Presentation
QtUtils is a set of tools to make using Qt5 more convenient.
I was tired of implementing again and again the same utilities company after company, so I decided to make an open-source library with these commonly used tools, so everyone can enjoy them.
Library Content
-
singleShotConnect
: Allows to create a single-shotQMetaObject::Connection
.1 2 3
oclero::singleShotConnect(this, &SomeClass::someSignalTriggered, []() { // Do stuff. });
-
QtScopedConnection
: RAIIQMetaObject::Connection
that will disconnect when destroyed.1 2 3
oclero::QtScopedConnection scopedConnection = QObject::connect(this, &SomeClass::someSignalTriggered, []() { // Do stuff. });
-
QtEnumUtils
: Utilities to convert enums toQString
orint
and vice-versa.1 2
auto str = oclero::enumToString(SomeEnum::SomeValue); auto value = oclero::enumFromString<SomeEnum>("SomeValue");
-
QtEventFilterUtils
: Utilities to quickly register to an event without the burden to create aclass
. All correspondingQEvent
-derived classes have been mapped to their correspondingQEvent::Type
, so you don’t even have to cast theQEvent
or worry about its type.1 2 3 4
oclero::EventFilter<QEvent::MouseButtonPress>::install(watchedObject, [](QMouseEvent* e) { // Do stuff, then return 'true' to block the event propagation, 'false' otherwise. return false; });
-
QtDeleteLaterScopedPointer
: A pointer manager likestd::unique_ptr
orQScopedPointer
, but callsdeleteLater()
instead ofdelete
.1
oclero::QtDeleteLaterScopedPointer<QObject> scopedPointer(rawPointer);
-
QtSettingsUtils
: Utilities to save and load strongly typed values fromQSettings
.1 2 3 4
QSettings settings; auto value = oclero::loadSetting<int>(settings, "key", 3 /* default value */); oclero::saveSetting(settings, "key", 3); oclero::clearSetting(settings, "key");
Information
- Repository: https://github.com/oclero/qtutils
- License: MIT