Results 1 to 3 of 3

Thread: metaObject() function retrieves exception

  1. #1

    Default metaObject() function retrieves exception

    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:


    Qt Code:
    1. PendingList *pendingMsgs = new PendingList(this, settings->value("GENERAL/CheckTimeoutInterval").toInt());
    2. const QMetaObject *meta = pendingMsgs->metaObject();
    To copy to clipboard, switch view to plain text mode 


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

    Qt Code:
    1. #include "MM.h"
    2. #include "Message.h"
    3. #include <QTimer>
    4.  
    5. struct PendingMsg
    6. {
    7. Message request; //message pending to receive a response
    8. CMD cmd; // type of the pending response {ACK or ORD_RESP}
    9. int timeout; // Time that can be stored the message before emitting a timeout signal
    10.  
    11. PendingMsg(Message m, CMD c, int t)
    12. {
    13. request = m;
    14. cmd = c;
    15. timeout = t;
    16. };
    17.  
    18. QString display() const
    19. {
    20. //return "[" + cmdTags[cmd] + " (" + cmdTags[request.getCmd()] + "), " + stateNames[newState] + "]";
    21. return "[" + cmdTags[cmd] + " (" + cmdTags[request.getCmd()] + ")]";
    22. };
    23. };
    24.  
    25. class PendingList : public QObject
    26. {
    27.  
    28. Q_OBJECT
    29.  
    30. public:
    31. PendingList(QObject* parent, int time);
    32. ~PendingList(void);
    33.  
    34. bool add(System sys, Message req, CMD cmd, int time);
    35. bool remove(System sys, CMD cmd);
    36.  
    37. void setCheckTimeInterval(int t) { checkTimeInterval = t;};
    38.  
    39. int size() const;
    40. void display() const;
    41.  
    42. private:
    43.  
    44. int checkTimeInterval;
    45. QTimer timer;
    46.  
    47. QList<PendingMsg> list[MAX_CLIENTS];
    48.  
    49. // finds the position of the command cmd inside list[sys]
    50. int match(System sys, CMD cmd) const;
    51.  
    52. bool startIfEmpty();
    53. bool stopIfEmpty();
    54.  
    55. // Reports that the system 'sys' has not sent a message of type 'cmd1' as answer of the message 'req'
    56. void emitTimeout(System sys, CMD cmd, Message req);
    57.  
    58. void emitMatch(System sys, CMD cmd, Message req);
    59.  
    60. private slots:
    61.  
    62. void checkTimeouts();
    63.  
    64. signals:
    65.  
    66. void timeout_ack_insp_mis(System);
    67. void timeout_ack_pause(System);
    68. void timeout_ack_abort(System);
    69. void timeout_ack_resume(System);
    70. void timeout_ack_mosaic(System);
    71. void timeout_ack_weed_map(System);
    72. void timeout_ack_tre_mis(System);
    73. void timeout_resp_insp_mis(System);
    74. void timeout_resp_pause(System);
    75. void timeout_resp_abort(System);
    76. void timeout_resp_resume(System);
    77. void timeout_resp_mosaic(System);
    78. void timeout_resp_weed_map(System);
    79. void timeout_resp_tre_mis(System);
    80.  
    81. void ack_insp_mis(System);
    82. void ack_mosaic(System);
    83. void ack_weed_map(System);
    84. void ack_tre_mis(System);
    85. void ack_unit_ctrl(System);
    86. void ack_abort(System);
    87. void ack_resume(System);
    88. void ack_pause(System);
    89. void resp_insp_mis(System);
    90. void resp_mosaic(System);
    91. void resp_weed_map(System);
    92. void resp_tre_mis(System);
    93. void resp_abort(System);
    94. void resp_resume(System);
    95. void resp_pause(System);
    96. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: metaObject() function retrieves exception

    This is the call to the function from the object pointer pendingMsgs which generates the exception:
    What is the exception?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3

    Default Re: metaObject() function retrieves exception

    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.

Similar Threads

  1. Replies: 0
    Last Post: 20th March 2013, 10:02
  2. Qt Guru Required for MetaObject system problem.
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 5th August 2011, 14:32
  3. QObject::MetaObject()
    By pkj in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2011, 10:41
  4. Replies: 1
    Last Post: 2nd June 2010, 16:14
  5. Example code and metaObject question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 12th January 2007, 18:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.