Having a bit of an issue with my Slots/Signals. I have distilled the code down to basics and am using it in a scratch project to help figure it out. I have run this in debug mode and placed a breakpoint in the moc file where the signal runs. Sure enough, it hits. However, the initStuff method is only being called once.
manager.h
#ifndef MANAGER_H
#define MANAGER_H
#include <QObject>
{
Q_OBJECT
public:
static Manager* instance();
static void init();
void start();
bool hasStuff() {return mStuff.size() > 0;}
private:
explicit Manager
(QObject *parent
= 0);
static Manager* _instance;
QList<Channel*> mStuff;
void processStuff();
void loadStuffQueue();
signals:
void emptyQueue();
public slots:
void initStuff();
};
#endif // MANAGER_H
#ifndef MANAGER_H
#define MANAGER_H
#include <QObject>
class Manager : public QObject
{
Q_OBJECT
public:
static Manager* instance();
static void init();
void start();
bool hasStuff() {return mStuff.size() > 0;}
private:
explicit Manager(QObject *parent = 0);
static Manager* _instance;
QList<Channel*> mStuff;
void processStuff();
void loadStuffQueue();
signals:
void emptyQueue();
public slots:
void initStuff();
};
#endif // MANAGER_H
To copy to clipboard, switch view to plain text mode
manager.cpp
#include "manager.h"
Manager
::Manager(QObject *parent
) :{
moveToThread(mThread);
}
void Manager::init()
{
_instance = new Manager();
connect(_instance, SIGNAL(emptyQueue()), _instance, SLOT(initStuff()));
_instance->initStuff();
_instance->start();
}
void Manager::start() {
if(mStuff.size() > 0) {
instance()->processStuff();
} else {
emit emptyQueue();
}
}
void Manager::initStuff()
{
//if there is stuff to put in the mStuff -- put it in there
}
void Manager::processStuff()
{
//here is where process stuff and empty the Stuff queue
//when queue is empty we emit
emit emptyQueue();
}
Manager* Manager::instance()
{
if (_instance == 0) {
_instance = new DSManager();
}
return _instance;
}
Manager* Manager::_instance;
#include "manager.h"
Manager::Manager(QObject *parent) :
QObject(parent)
{
mThread = new QThread(0);
moveToThread(mThread);
}
void Manager::init()
{
_instance = new Manager();
connect(_instance, SIGNAL(emptyQueue()), _instance, SLOT(initStuff()));
_instance->initStuff();
_instance->start();
}
void Manager::start() {
if(mStuff.size() > 0) {
instance()->processStuff();
} else {
emit emptyQueue();
}
}
void Manager::initStuff()
{
//if there is stuff to put in the mStuff -- put it in there
}
void Manager::processStuff()
{
//here is where process stuff and empty the Stuff queue
//when queue is empty we emit
emit emptyQueue();
}
Manager* Manager::instance()
{
if (_instance == 0) {
_instance = new DSManager();
}
return _instance;
}
Manager* Manager::_instance;
To copy to clipboard, switch view to plain text mode
main.cpp — relevant code
Manager::init();
Manager::init();
To copy to clipboard, switch view to plain text mode
Bookmarks