[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

    @#ifndef REQUESTPOST_H
    #define REQUESTPOST_H

    #include <QObject>
    #include <QtNetwork/QNetworkRequest>
    #include <QtNetwork/QNetworkReply>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QUrl>

    class RequestPost:public QObject
    {
    // Q_OBJECT

    public:
    RequestPost();
    void connection( QByteArray postData,const QString& url);
    QIODevice *networkReply() const;
    private:
    QNetworkReply *reply;
    QNetworkAccessManager *manager;

    private slots:
    void finishedSlot();

    };
    #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.



  • 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.



  • 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



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.