PDA

View Full Version : metaObject() function retrieves exception



ClintEastwood
23rd April 2013, 12:03
Hello all:

I have defined a new class which inherits from QObject but when I try to invoke the QObject::metaObject() function from an instance of this object I get an access violation exception. Does anyone know why I cannot call the QObject::metaObject() function???

This is the call to the function from the object pointer pendingMsgs which generates the exception:




PendingList *pendingMsgs = new PendingList(this, settings->value("GENERAL/CheckTimeoutInterval").toInt());
const QMetaObject *meta = pendingMsgs->metaObject();



And this is the class that I have defined (PendingList):



#include "MM.h"
#include "Message.h"
#include <QTimer>

struct PendingMsg
{
Message request; //message pending to receive a response
CMD cmd; // type of the pending response {ACK or ORD_RESP}
int timeout; // Time that can be stored the message before emitting a timeout signal

PendingMsg(Message m, CMD c, int t)
{
request = m;
cmd = c;
timeout = t;
};

QString display() const
{
//return "[" + cmdTags[cmd] + " (" + cmdTags[request.getCmd()] + "), " + stateNames[newState] + "]";
return "[" + cmdTags[cmd] + " (" + cmdTags[request.getCmd()] + ")]";
};
};

class PendingList : public QObject
{

Q_OBJECT

public:
PendingList(QObject* parent, int time);
~PendingList(void);

bool add(System sys, Message req, CMD cmd, int time);
bool remove(System sys, CMD cmd);

void setCheckTimeInterval(int t) { checkTimeInterval = t;};

int size() const;
void display() const;

private:

int checkTimeInterval;
QTimer timer;

QList<PendingMsg> list[MAX_CLIENTS];

// finds the position of the command cmd inside list[sys]
int match(System sys, CMD cmd) const;

bool startIfEmpty();
bool stopIfEmpty();

// Reports that the system 'sys' has not sent a message of type 'cmd1' as answer of the message 'req'
void emitTimeout(System sys, CMD cmd, Message req);

void emitMatch(System sys, CMD cmd, Message req);

private slots:

void checkTimeouts();

signals:

void timeout_ack_insp_mis(System);
void timeout_ack_pause(System);
void timeout_ack_abort(System);
void timeout_ack_resume(System);
void timeout_ack_mosaic(System);
void timeout_ack_weed_map(System);
void timeout_ack_tre_mis(System);
void timeout_resp_insp_mis(System);
void timeout_resp_pause(System);
void timeout_resp_abort(System);
void timeout_resp_resume(System);
void timeout_resp_mosaic(System);
void timeout_resp_weed_map(System);
void timeout_resp_tre_mis(System);

void ack_insp_mis(System);
void ack_mosaic(System);
void ack_weed_map(System);
void ack_tre_mis(System);
void ack_unit_ctrl(System);
void ack_abort(System);
void ack_resume(System);
void ack_pause(System);
void resp_insp_mis(System);
void resp_mosaic(System);
void resp_weed_map(System);
void resp_tre_mis(System);
void resp_abort(System);
void resp_resume(System);
void resp_pause(System);
};

Santosh Reddy
23rd April 2013, 12:44
This is the call to the function from the object pointer pendingMsgs which generates the exception:
What is the exception?

ClintEastwood
23rd April 2013, 13:07
Sorry, I have found the problem. I was not executing the above first 2 instructions in the order I thought. I was calling the metaobject() function from a non initialized pointer... My apologies for the inconveniences caused.