Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Q_OBJECT and vtable
Forum Updated to NodeBB v4.3 + New Features

[Solved]Q_OBJECT and vtable

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toho71
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          miroslav
          wrote on last edited by
          #4

          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.

          Mirko Boehm | mirko@kde.org | KDE e.V.
          FSFE Fellow
          Qt Certified Specialist

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toho71
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved