refs #794 Utility function to establish a signal/slot connection that auto-disconnects upon the first delivery.

This commit is contained in:
Mathew Sutcliffe
2016-10-31 00:21:12 +00:00
committed by Klaus Basan
parent ab8dcbad97
commit 4ed72706fc
2 changed files with 37 additions and 6 deletions

View File

@@ -20,6 +20,7 @@
#include "blackmisc/metaclass.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/range.h"
#include "blackmisc/slot.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/valuecacheprivate.h"
#include "blackmisc/variant.h"
@@ -441,12 +442,7 @@ namespace BlackMisc
//! \private Connect a function to be called (only once) when the owner's objectName changes.
void onOwnerNameChanged(std::function<void()> function)
{
auto connection = std::make_shared<QMetaObject::Connection>();
*connection = QObject::connect(m_page->parent(), &QObject::objectNameChanged, [connection, function](const QString &)
{
QObject::disconnect(*connection);
function();
});
connectOnce(m_page->parent(), &QObject::objectNameChanged, [function](const QString &) { function(); });
}
Private::CValuePage *m_page = (qFatal("Must be initialized"), nullptr); //!< \private