Important: Please read the Qt Code of Conduct -

[SOLVED] Problem when create an Object : Undefiner reference

  • Hi all,

    i don't understand the problem becuse the "undefine references" error s tu approssimative for debug and in my code is all defined but:

    QList<Oggetto*> InterfacciaDataModel::convertitore(QList<MeteoLocale> lista){
    QList<Oggetto*> listToReturn;

    for(int i=0; i < lista.count(); i++) {
    Oggetto oggetto(; // here there are an error: undefined reference to Oggetto::Oggetto(QHash<QString, QString>)' listToReturn.append(&oggetto); } // and here i have the same error but for destructor: undefined reference toOggetto::~Oggetto()'

    return listToReturn;

    in my .h file of Oggetto i define both method:

    #include <QObject>
    #include <QHash>

    class Oggetto: public QObject {


    Oggetto(QHash<QString, QString> param);
    virtual ~Oggetto();

    QHash<QString, QString> property;

    and avery one can see the definition in the .cpp file:

    @#include "Oggetto.h"

    Oggetto::Oggetto(QHash<QString, QString> param) {
    // TODO Auto-generated constructor stub



    Oggetto::~Oggetto() {
    // TODO Auto-generated destructor stub

    anione know why i have this error??

    regards to all

  • Try re-running qmake, and rebuilding. I think you added Q_OBJECT later on. Q_OBJECT defines some methods, the implementation of which will be auto-generated by moc. However, moc is probably not ran on your header. It is those methods that are missing, I think.

  • sorry there is a problem... i'm develop for BB10 and i not have the option for rerun qmake... i have try to Clean project and re build but the error remaning...

  • Try removing moc_* files, or removing your .h and .cpp file from project and then adding them back.

    Like Andre said, this is very likely a qmake related issue, and cleaning all you build files manually should fix it.

  • I have solved problem deleting project and re import all class in a new object but i have see in the includ of the header:

    @HEADERS +=

    now are present in the iold project missing... i think that this is the problem.. Tanks to all!! :)

  • Eh, yes. Obviously. You should just list all headers in there. Saves you a lot of headaches.

Log in to reply