Description
sling is a lightweight C++ implementation of signals and slots. A slot is essentially a callback wrapper which can be created from different kinds of callable entities. Slots can be connected to a signal, and they get notified when the signal is emitted.
sling alternatives and similar libraries
Based on the "GUI" category.
Alternatively, view sling alternatives based on common mentions on social networks and blogs.
-
webview
Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows). -
libui
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports. -
FTXUI
Features: - Functional style. Inspired by [1] and React - Simple and elegant syntax (in my opinion). - Support for UTF8 and fullwidth chars (→ 测试). - No dependencies. - Cross platform. Linux/mac (main target), Windows (experimental thanks to contributors), - WebAssembly. - Keyboard & mouse navigation. Operating systems: - linux emscripten - linux gcc - linux clang - windows msvc - mac clang -
SixtyFPS
DISCONTINUED. Slint is a toolkit to efficiently develop fluid graphical user interfaces for any display: embedded devices and desktop applications. We support multiple programming languages, such as Rust, C++ or JavaScript. [Moved to: https://github.com/slint-ui/slint] -
GacUI
GPU Accelerated C++ User Interface, with WYSIWYG developing tools, XML supports, built-in data binding and MVVM features. -
Turbo Vision
A modern port of Turbo Vision 2.0, the classical framework for text-based user interfaces. Now cross-platform and with Unicode support. -
cuda-api-wrappers
Thin C++-flavored header-only wrappers for core CUDA APIs: Runtime, Driver, NVRTC, NVTX. -
xtd
Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications and libraries on Microsoft Windows, Apple macOS and Linux. -
CTPG
Compile Time Parser Generator is a C++ single header library which takes a language description as a C++ code and turns it into a LR1 table parser with a deterministic finite automaton lexical analyzer, all in compile time. -
ncurses
snapshots of ncurses - see http://invisible-island.net/ncurses/ncurses.faq.html (no pull requests are accepted) -
fox-toolkit
Unofficial Zenotech specific mirror of fox-toolkit; please refer to upstream site for latest version -
NotificationManager
A thread-safe, easy-to-use, utility for sending and receiving notifications. It allows you to decouple different modules of your application. -
QwtPlot3D
A feature-rich Qt/OpenGL-based C++ programming library, providing essentially a bunch of 3D-widgets. [zlib]
WorkOS - The modern identity platform for B2B SaaS
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of sling or a related project?
Popular Comparisons
README
sling
sling is a lightweight C++ implementation of signals and slots. A slot is essentially a callback wrapper which can be created from different kinds of callable entities. Slots can be connected to a signal, and they get notified when the signal is emitted.
Installation
Being a header-only library, you can just include it in your project. Requires compiler support for C++11 or later.
Usage
Creating signals
sl::Signal<> sig0; // signal without parameters.
sl::Signal<std::string> sig1; // signal with one parameter (std::string).
sl::Signal<double, int> sig2; // signal with two parameters (double and int).
Connecting slots
sl::Signal<int> sig;
Connect slots created from lambda expressions.
sig.connect(sl::Slot<int>([](int x) {}));
Connect slots created from regular functions.
void foo(int x) {}
sig.connect(sl::Slot<int>(foo));
Connect slots created from object member functions.
class Foo
{
public:
void bar(int x) {}
void baz(int x) const {}
virtual void qux(int x) {}
static void corge(int x) {}
};
Foo foo;
sig.connect(sl::Slot<int>(&foo, &Foo::bar));
sig.connect(sl::Slot<int>(&foo, &Foo::baz));
sig.connect(sl::Slot<int>(&foo, &Foo::qux));
sig.connect(sl::Slot<int>(Foo::corge));
Connect slots created from object instances implementing operator ().
struct Bar
{
void operator () (int x) const {}
};
sig.connect(sl::Slot<int>(Bar()));
Disconnecting slots
void foo(int x) {}
sl::Signal<int> sig;
Disconnect using the slot interface.
sl::Slot<int> slot(foo);
sig.connect(slot);
slot.disconnect();
Disconnect by passing a reference or a pointer to the slot.
sl::Slot<int> slot(foo);
sig.connect(slot);
sig.disconnect(slot); // or sig.disconnect(&slot);
Disconnect by passing the slot key returned on signal connection.
sl::SlotKey key = sig.connect(sl::Slot<int>(foo));
sig.disconnect(key);
Disconnect all slots.
sig.clear();
All slots are automatically disconnected when the signal they are connected to goes out of scope. Similarly, slots are automatically disconnected from signals when they go out of scope.
Slots are suitable as public class members, as they are automatically disconnected when the class instance they belong to goes out of scope. In addition, this allows private member functions to be specified as slot callbacks.
class Baz
{
private:
void bar(int x) {}
public:
sl::Slot<int> onBar{this, &Baz::bar};
};
Baz b;
sig.connect(b.onBar);
Emitting signals
sl::Signal<int> sig;
sig(1); // or sig.emit(1);
Copying and moving
Signal copying is disabled as I have not found an intuitive behaviour for this operation. Moving signals is allowed and it transfers all connected slots to the new signal. The moved signal is left in a valid state, as if newly constructed.
Slot copying is permitted and the result of the operation is a slot having a
copy of the source slot callback. However, the new slot is not connected to the
signal the original slot is connected to, if any. When moving slots, the new
slot basically replaces the old one. If the moved slot is connected to a signal,
it is disconnected first, and the new one is connected to that signal.
The moved slot is left in a valid state, having no callback. A new callback
can be assigned using the setCallback
method.
Thread safety
The library does not guarantee thread safety in its current state. I am considering making it thread safe in the future.
Contributing
Contributions in the form of pull requests, issues or just general feedback, are always welcome. See CONTRIBUTING.MD.
License
Copyright (c) 2019 Adrian-George Bostan.
This project is licensed under the MIT license. See LICENSE for more details.
*Note that all licence references and agreements mentioned in the sling README section above
are relevant to that project's source code only.