0

I've been trying to create a timer that every time it runs out it will add something to a list. To do this i need to add a slot to the signal of the timer running out.

#ifndef GAMEMODEL_H
#define GAMEMODEL_H

#include <QObject>
#include <QTimer>


class GameModel: public QObject{
    Q_OBJECT
private:
    listaLinkata<Energy> *energySources;
    QTimer* energyTimer;

public:
    explicit GameModel(QObject *parent = nullptr);
    ~GameModel() = default;

    void addEnergy(const Energy& energyItem);

private slots:
    void generateEnergy();

};

#endif // GAMEMODEL_H

.cpp
#include "gamemodel.h"
#include <QTimer>


GameModel::GameModel(QObject *parent) : QObject(parent)
{ 
    energyTimer = new QTimer(this);
    energyTimer->setInterval(30000);

    QObject::connect(energyTimer, &QTimer::timeout, this, &GameModel::generateEnergy);

    energyTimer->start();
}

//this is the slot and assume the functions inside are working.
void GameModel::generateEnergy() {
        Energy newEnergy("NewEnergy");
        addEnergy(newEnergy);
    }
}


and this is the error tham I'm facing.

:-1: error: debug/main.o:main.cpp:(.rdata$.refptr._ZTV9GameModel[.refptr._ZTV9GameModel]+0x0): undefined reference to `vtable for GameModel'

I can't make the slot work, no matter the changes I do. I'm already using a slot and signal on my main and even on a View and they work, why not here? Btw, I'm using an MVC pattern not that matters for this particualr problem.

I tried with chatGPT but that thing is telling me to create dummy functions to override something from QObject but in the end nothing worked. After that it told me to check if I've iherithed from QObject correctly and I think I did.

  • Have you run qmake? – 273K Aug 25 '23 at 15:38
  • im using QtCreator and i just build and run the project, how do i manually run qumake? – Alcky26 Aug 25 '23 at 15:40
  • OH WELL how embaracing, since i'm on windows every new file i create it is automatically renamed with lowercase and i just opened the .pro and renamed everything with the same uppercase i used when creating those files and now its working... yeah.. im not too sure why though. – Alcky26 Aug 25 '23 at 15:52
  • Windows filesystems are case insensitive but case preserving by default unless you enabled case sensitivity. – drescherjm Aug 25 '23 at 16:08

0 Answers0