Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Signal isn't recognized after connecting it to a slot
Forum Updated to NodeBB v4.3 + New Features

Signal isn't recognized after connecting it to a slot

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
13 Posts 3 Posters 489 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.
  • J Offline
    J Offline
    Jay_emissary
    wrote last edited by
    #1

    Hey all,
    I've created a timestep class to manage all my deltatime calculations. After a timer goes off, I run this code:

    signals:
        void Tick(float deltatime);
    public:
    void CalculateTimeStep(){
            deltaTime = (CurrentRuntime - TimeSinceLastRuntimeUpdate) / 1000.0f;
            TimeSinceLastRuntimeUpdate = CurrentRuntime;
    
            qDebug() << "timestep complete";
            emit Tick(deltaTime);
        }
    

    When I use qDebug to test the function, the message goes through and the emitter fires. With that said, how come when I try and connect the signal to one of my QObjects (GameInitializer), the function never fires?

    From my GameInitializer class:

    void GameInitializer::Tick(int deltatime)
    {
        conductor->Tick(deltaTimer->deltaTime);
        gameManager->Tick(deltaTimer->deltaTime);
        qDebug() << deltaTimer <<gameManager << "l" << deltatime;
    }
    
    void GameInitializer::Setup(){
        //Required to calculate Timestep
        QElapsedTimer runtimeTimer;
        runtimeTimer.start();
    
        qmlRegisterType<HitObject>("HitObject", 1,0, "HitObject");
    
        deltaTimer = new TimeStep(this, 16, (float)runtimeTimer.elapsed());
        connect(deltaTimer, &TimeStep::Tick, this, &GameInitializer::Tick);
    

    The funny thing is, when I fire the emitter manually, GameInitializer::Tick actually runs. Perhaps I'm setting the signals and slots up the wrong way?

    This works:

        connect(deltaTimer, &TimeStep::Tick, this, &GameInitializer::Tick);
        emit deltaTimer->Tick(3);
    

    But not the emitter in the timestep class?? Again the function fires the message, so I know it works, but the signal isn't going through...

    I'd love to get some further insight on how to fix this issue, thanks!

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

      Start over with a simple main.cpp

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

      J 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote last edited by
        #2

        Hi,

        Where/when is CalculateTimeStep called ?

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

        J 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Where/when is CalculateTimeStep called ?

          J Offline
          J Offline
          Jay_emissary
          wrote last edited by
          #3

          @SGaist CalculateTimeStep is being called in a header file. I figured that I wouldn't need the .cpp file since I'm only using three mini-functions throughout the entire class. Additionally, I could have classes inherit these functions later.

          CalculateTimeStep is called from a timer that's inside StartTimeStepTimer();

              void StartTimeStepTimer(){
                  QTimer* updateTimer = new QTimer(this);
                  QObject::connect(updateTimer, &QTimer::timeout, this, &TimeStep::CalculateTimeStep);
                  updateTimer->start(FPSms); 
              }
          
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by
            #4

            And where is StartTimeStepTimer() called?
            Please provide a minimal, compilable example to reproduce your problem.

            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
            • J Offline
              J Offline
              Jay_emissary
              wrote last edited by
              #5

              I'm sorry, but now that you've mentioned it and after taking another look at my code, I think the problem lies within the fact that I forgot to call StartTimeStepTimer in the initializer class, my bad. I would test to verify that, but unfortunately, I've come across another issue, and I can't compile without fixing it first. I haven't done anything to my project to cause an error like this, so I'm not sure what I can do to fix it... I've already tried reinstalling Qt Creator, but I can't seem to shake the error. Are you familiar with anything like this?

              image.png

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jay_emissary
                wrote last edited by Jay_emissary
                #6

                As far as I know, the error from the image stems from the QGuiApplication file, which I've never touched. This one error is causing a domino effect, leading to about a hundred other ambiguous errors. Strangely, it's specific to this project, despite the fact that I haven't added anything to warrant an error like this. I've also tried cleaning and rebuilding the project from the IDE, but that also doesn't help. If I could get some help with this, I'd be ever so grateful.

                gameinitializer.h:3:10: In included file: no member named 'clock_t' in the global namespace; did you mean 'clockid_t'?
                ctime:60:11: error occurred here
                pthread.h:382:13: 'clockid_t' declared he

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jay_emissary
                  wrote last edited by
                  #7

                  I've just realized that the image I sent can be a little misleading, so I have a couple of other images, proving that the error doesn't just come from the game initializer class; no matter where I go in the project. The error always shows up somewhere at the top.

                  image.png
                  image.png

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

                    Show the relevant header, maybe you added a using namespace or forgot the ; at the end of the class.

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

                    J 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      Show the relevant header, maybe you added a using namespace or forgot the ; at the end of the class.

                      J Offline
                      J Offline
                      Jay_emissary
                      wrote last edited by Jay_emissary
                      #9

                      @Christian-Ehrlicher That's my problem. Because the error points to many different header files, it's hard to tell which one is truly relevant. Excuse me for using images, but there's too much code here, and because I'm a new user, Qt flags my posts as spam if there are too many characters.

                      All the errors point to this file, which I never touch (it's engine related)
                      e9a20f36-f82e-4adc-8c64-1dbf6d5071d9-image.png !

                      the error that always appears at the top points to the engine-related header files in my project...
                      d01a0973-4d90-4fb5-b459-285926244f51-image.png

                      d006426d-cea6-4930-9ffb-71a5759cdab3-image.png

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

                        Start over with a simple main.cpp

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

                        J 1 Reply Last reply
                        2
                        • J Jay_emissary has marked this topic as solved
                        • Christian EhrlicherC Christian Ehrlicher

                          Start over with a simple main.cpp

                          J Offline
                          J Offline
                          Jay_emissary
                          wrote last edited by
                          #11

                          @Christian-Ehrlicher
                          Hey, so after a bit of research yesterday, I found that when you have a file names time.cpp/time.h in your project, Qt gets confused and throws this exact error. The files didn't show up in my Qt project manager, so I didn't realize that they were for some reason in my project, but as I was moving my files to a clean project like you suggested, I found that both time.cpp and time.h were sitting in my project files! I removed them and it worked perfectly. Thank you so much for the recommendation!

                          here's the stack overflow page I was reading yesterday
                          https://stackoverflow.com/questions/43813563/clock-t-and-clock-in-does-not-declared-in-this-scope-in-qt

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

                            This has nothing to do with Qt - you must not use a filename which is also used by the c or c++ system headers which you did.

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

                            J 1 Reply Last reply
                            0
                            • Christian EhrlicherC Christian Ehrlicher

                              This has nothing to do with Qt - you must not use a filename which is also used by the c or c++ system headers which you did.

                              J Offline
                              J Offline
                              Jay_emissary
                              wrote last edited by
                              #13

                              @Christian-Ehrlicher Noted.

                              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