Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(model): return connection from interface macro
Browse files Browse the repository at this point in the history
connection is normally returned from Qt's connect, and the caller may want to
track the connection to manually disconnect it.

(cherry picked from commit 41b2b35)
  • Loading branch information
anthonybilinski committed Mar 20, 2020
1 parent dfeca3e commit 40e4358
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/model/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef INTERFACE_H
#define INTERFACE_H

#include <QMetaObject>

#include <functional>

/**
Expand Down Expand Up @@ -48,15 +50,15 @@
*/
#define DECLARE_SIGNAL(name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \
virtual void connectTo_##name(Slot_##name slot) const = 0
virtual QMetaObject::Connection connectTo_##name(Slot_##name slot) const = 0

/**
* @def DECLARE_SIGNAL
* @brief Decalre signal-like method. Should be used in interface
*/
#define DECLARE_SIGNAL(name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \
virtual void connectTo_##name(Slot_##name slot) const = 0
virtual QMetaObject::Connection connectTo_##name(Slot_##name slot) const = 0

/**
* @def SIGNAL_IMPL
Expand All @@ -65,7 +67,7 @@
#define SIGNAL_IMPL(classname, name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \
Q_SIGNAL void name(__VA_ARGS__); \
void connectTo_##name(Slot_##name slot) const override { \
QMetaObject::Connection connectTo_##name(Slot_##name slot) const override { \
connect(this, &classname::name, slot); \
}

Expand Down

0 comments on commit 40e4358

Please sign in to comment.