February 1, 2012

toho71 toho71
Lab Rat
189 posts

[Solved]Q_OBJECT and vtable

 

When i put QObject in my H file I got this message

:/requestpost.cpp:4: undefined reference to `vtable for RequestPost’

My headerFile

  1. #ifndef REQUESTPOST_H
  2. #define REQUESTPOST_H
  3.  
  4. #include <QObject>
  5. #include <QtNetwork/QNetworkRequest>
  6. #include <QtNetwork/QNetworkReply>
  7. #include <QtNetwork/QNetworkAccessManager>
  8. #include <QUrl>
  9.  
  10. class RequestPost:public QObject
  11. {
  12. //    Q_OBJECT
  13.  
  14. public:
  15.     RequestPost();
  16.     void connection( QByteArray postData,const QString& url);
  17.     QIODevice *networkReply() const;
  18. private:
  19.     QNetworkReply *reply;
  20.     QNetworkAccessManager *manager;
  21.  
  22. private slots:
  23.     void finishedSlot();
  24.  
  25. };
  26. #endif // REQUESTPOST_H

I have done in a similar way a lots of times earlier and never got this problem.
Anyone who could tell me why this problem appers in this class declaration.

4 replies

February 1, 2012

Asperamanca Asperamanca
Hobby Entomologist
372 posts

I’ve never seen Q_OBJECT under comment.

Normally, you can resolve such issues by cleaning the project, then running qmake, and then rebuild.

If you want to be more specific, it should be enough to manually delete all generated files for that class – that is, the corresponding moc-File (if one even existed), and the corresponding object files, and then run qmake and build the project.

February 1, 2012

toho71 toho71
Lab Rat
189 posts

I comment the QObject so that the prj could work.
It,s very strange because I did an almost exactly class and it worked just fine.
bq. But I’ll try your tip.

It worked now

Thank you

February 1, 2012

miroslav miroslav
Ant Farmer
228 posts

Since Q_OBJECT is commented out, qmake probably won’t generate compile steps for the moc file. Uncomment it and run qmake again. If that does not fix it, poke again please.

 Signature 

Mirko Boehm | .(JavaScript must be enabled to view this email address) | KDE e.V.
FSFE Fellow
Qt Certified Specialist

February 1, 2012

toho71 toho71
Lab Rat
189 posts

It helped when I took the .o file away.
The comment was as I mentioned before just a lucky hit when I tried to get what went wrong when I builded my class.

 
  ‹‹ QTcpSocket problem      Help!!!! ››

You must log in to post a reply. Not a member yet? Register here!