Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal is emitted, slot is not running
Forum Updated to NodeBB v4.3 + New Features

Signal is emitted, slot is not running

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JasonKretzer
    wrote on last edited by
    #1

    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>

    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
    @

    manager.cpp
    @
    #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;
    @

    main.cpp -- relevant code
    @
    Manager::init();
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Did you place a break point on
      @
      emit emptyQueue()
      @
      Did you check the return value of connect is true?
      Was there an output concerning the connect?

      You do not specify the on what system you are running and what your IDE is.
      Is it qt creator? There you should see outputs in the application output window.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JasonKretzer
        wrote on last edited by
        #3

        yes, it hit that breakpoint.

        yes, the connect returns true.

        no output concerning the connect on run or build.

        I am using Qt5.0.2 and qtcreator on Win7.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Buckets
          wrote on last edited by
          #4

          even thought the connect is returning true, it isn't behaving like you want it to. Why don't you just call initStuff instead of having a signal for it?

          ba ba ba
          ba na na na

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Buckets
            wrote on last edited by
            #5

            @void Manager::start() {
            if(mStuff.size() > 0) {
            instance()->processStuff();
            } else {
            initStuff();
            }
            }@

            and
            @void Manager::processStuff()
            {
            //here is where process stuff and empty the Stuff queue
            //when queue is empty we emit
            initStuff();
            }@
            work

            but looking at your code you call initStuff at the end of processStuff and in the else section of start().

            Why not just
            @void Manager::processStuff()
            {
            //here is where process stuff and empty the Stuff queue
            }
            void Manager::start() {
            if(mStuff.size() > 0) {
            instance()->processStuff();
            }
            initStuff();
            }
            @

            ba ba ba
            ba na na na

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved