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. implementing my own QTimer: never signals the slot?
Forum Updated to NodeBB v4.3 + New Features

implementing my own QTimer: never signals the slot?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 643 Views 2 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by davecotter
    #1

    here's my cute little timer impl:

    class QKJamsTimer : public QObject {
    	typedef QObject		_inherited;
    	
    	//Q_OBJECT
    
    	QTimer			i_timer;
    	bool			i_first_timeB;
    	APP_ForkInfo		*i_forkInfoP;
    	APP_TimerForkData	*i_timerDataP;
    	
    	public:
    	QKJamsTimer(APP_ForkInfo *forkInfoP) :
    		i_timer(this),
    		i_first_timeB(true),
    		i_timerDataP((APP_TimerForkData *)forkInfoP->dataP), 
    		i_forkInfoP(forkInfoP)
    	{
    		Duration		delayMs(i_timerDataP->GetDelayTime() * kMiliSPerSecond);
    		
    		connect(&i_timer, SIGNAL(timeout()), this, SLOT(timer_fired()));
    		i_timer.start(delayMs);
    	}
    	
    	//	time in seconds
    	void		setFireInterval(EventTimerInterval intervalF)
    	{
    		Duration		intervalMs(intervalF * kMiliSPerSecond);
    
    		i_timer.setInterval(intervalMs);
    	}
    	
    	public Q_SLOTS:
    	void		timer_fired()
    	{
    		OSErr					err = noErr;
    		
    		if (i_first_timeB) {
    			i_first_timeB = false;
    	
    			/*
    				we can't separately set the delay time
    				and the fire time, so the FIRST fire time
    				is the delay time, and subsequent fire
    				times are regular ones.
    			*/
    
    			// note that i_timerDataP->SetFireInterval() just calls back into this->setFireInterval()
    			i_timerDataP->SetFireInterval(i_timerDataP->GetFireInterval());
    		}
    		
    		XTE(err = i_forkInfoP->thiz->CB_Fork(i_forkInfoP));
    		PostThreadError("Fork Timer Error", err);
    	}
    };
    

    I couldn't make my object derive from QTimer itself, since you have to pass this into it, and that crashes, so i made it "has-a" instead of "is-a".

    I can't un-comment Q_OBJECT because then my app won't link due to this:

    "vtable for QKJamsTimer", referenced from:
        QKJamsTimer::QKJamsTimer(APP_ForkInfo*) in CThreads.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    

    but all funcs ARE inline so.... ¯\_(ツ)_/¯

    the deal is:
    1: i can't set breakpoints into thetimer_fired()function, they just disappear and go down to the next line of executable code, fa below this class and
    2: thetimer_fired()slot is never called

    what am i missing?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #7

      that was it!

      i put the class defs into the header, re-ran qmake, and now all is well. thanks for the hint!

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        You need Q_OBJECT if you want to use old style signal/slots ... you will see a runtime warning that the connect failed (and connect will also return false)...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • D Offline
          D Offline
          davecotter
          wrote on last edited by
          #3

          are there ... new style signals / slots? if so, how?

          or, how do i get past the link error mentioned above when i attempt to includeQ_OBJECT?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            The Signals & Slots chapter of QT's documentation explains that.

            Did you check the value of the interval you set ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • D Offline
              D Offline
              davecotter
              wrote on last edited by davecotter
              #5

              @SGaist i hope they pay you a full time salary, you are the most awesome helpful person i've ever met.

              yes, the value is correct. okay so according to the doc:

              We recommend using the qmake makefile generation tool for building your makefiles. This tool
              generates a makefile that does all the necessary moc handling... If you use qmake, try rerunning 
              it to update your makefile. This should do the trick
              

              okay, well that sounds promising, except for:

              1. I AM using qmake
              2. i did re-run qmake
              3. same problem

              it mentions editing the make file but won't that just get over-written next time i run qmake? do i need to do anything special BESIDES run qmake? do i need to, in my .pro file, mark this file as requiring moc then include the moc-generated file?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #6

                TIDBIT: this class is in a C++ file. i think i must inform my .pro file somehow to run moc over it??

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by
                  #7

                  that was it!

                  i put the class defs into the header, re-ran qmake, and now all is well. thanks for the hint!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    If you define classes in .cpp files you have to add #include "name_of_file.moc" for qmake to find that moc has to process that file to find said classe there.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    • Login

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