Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Signal is emitted, slot is not running

    General and Desktop
    3
    5
    1048
    Loading More Posts
    • 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
      JasonKretzer last edited by

      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 Reply Quote 0
      • K
        koahnig last edited by

        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 Reply Quote 0
        • J
          JasonKretzer last edited by

          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 Reply Quote 0
          • B
            Buckets last edited by

            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 Reply Quote 0
            • B
              Buckets last edited by

              @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 Reply Quote 0
              • First post
                Last post