properly hook SharedNodePointer for signals/slots

This commit is contained in:
Stephen Birarda 2014-01-13 17:17:53 -08:00
parent 7d1a64ca8c
commit 677303b5c0
3 changed files with 9 additions and 4 deletions

View file

@ -25,7 +25,8 @@
#include "NodeData.h"
#include "SimpleMovingAverage.h"
class Node {
class Node : public QObject {
Q_OBJECT
public:
Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
~Node();

View file

@ -36,6 +36,9 @@ NodeList* NodeList::_sharedInstance = NULL;
NodeList* NodeList::createInstance(char ownerType, unsigned short int socketListenPort) {
if (!_sharedInstance) {
_sharedInstance = new NodeList(ownerType, socketListenPort);
// register the SharedNodePointer meta-type for signals/slots
qRegisterMetaType<SharedNodePointer>();
} else {
qDebug("NodeList createInstance called with existing instance.");
}
@ -682,7 +685,7 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
// we didn't have this node, so add them
Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket);
NodeHash::iterator addedItem = _nodeHash.insert(newNode->getUUID(), SharedNodePointer(newNode));
NodeHash::iterator addedItem = _nodeHash.insert(newNode->getUUID(), SharedNodePointer(newNode, &QObject::deleteLater));
qDebug() << "Added" << *newNode << "\n";

View file

@ -52,6 +52,7 @@ public:
typedef QSharedPointer<Node> SharedNodePointer;
typedef QHash<QUuid, SharedNodePointer> NodeHash;
Q_DECLARE_METATYPE(SharedNodePointer)
class NodeList : public QObject {
Q_OBJECT
@ -128,8 +129,8 @@ public slots:
void pingInactiveNodes();
void removeSilentNodes();
signals:
void nodeAdded(QSharedPointer<Node>);
void nodeKilled(QSharedPointer<Node>);
void nodeAdded(SharedNodePointer);
void nodeKilled(SharedNodePointer);
private:
static NodeList* _sharedInstance;