Results 1 to 4 of 4

Thread: Problems with MOC, vtable error

  1. #1
    Join Date
    Apr 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problems with MOC, vtable error

    I read similar threads but they didn't help me.
    What's wrong with my code?
    the file is included in the pro file.
    Anyway there are errors about vtable...

    #ifndef CUBE_H
    #define CUBE_H

    #include <QObject>

    class cube: public QObject
    {
    Q_OBJECT

    public:
    explicit cube(QObject *parent=0)
    {
    for(int i=0; i<9; i++)
    {
    front[i]=Qt::white;
    back[i]=Qt::yellow;
    up[i]=Qt::green;
    down[i]=Qt::blue;
    left[i]=Qt::red;
    right[i]=Qt::magenta;
    }
    }

    ~cube()
    {
    }

    public:
    void draw(QPainter & painter);

    void moveFront();
    void moveBack();
    void moveUp();
    void moveDown();
    void moveLeft();
    void moveRight();
    void moveFrontInverted();
    void moveBackInverted();
    void moveUpInverted();
    void moveDownInverted();
    void moveLeftInverted();
    void moveRightInverted();
    void rotateSide(Qt::GlobalColor side[9]);
    void rotateSideInverted(Qt::GlobalColor side[9]);
    void rotateRibs(Qt::GlobalColor &a1, Qt::GlobalColor &a2, Qt::GlobalColor &a3, Qt::GlobalColor &b1, Qt::GlobalColor &b2, Qt::GlobalColor &b3, Qt::GlobalColor &c1, Qt::GlobalColor &c2, Qt::GlobalColor &c3, Qt::GlobalColor &d1, Qt::GlobalColor &d2, Qt::GlobalColor &d3);
    void rotateRibsInverted(Qt::GlobalColor &a1, Qt::GlobalColor &a2, Qt::GlobalColor &a3, Qt::GlobalColor &b1, Qt::GlobalColor &b2, Qt::GlobalColor &b3, Qt::GlobalColor &c1, Qt::GlobalColor &c2, Qt::GlobalColor &c3, Qt::GlobalColor &d1, Qt::GlobalColor &d2, Qt::GlobalColor &d3);

    private:
    Qt::GlobalColor front[9];
    Qt::GlobalColor back[9];
    Qt::GlobalColor up[9];
    Qt::GlobalColor down[9];
    Qt::GlobalColor left[9];
    Qt::GlobalColor right[9];

    signals:
    void changed();
    };

    #endif // CUBE_H


    Added after 37 minutes:


    the problem is with the QtCreator, because the code works well being compiling manually with qmake and make utilities.
    What can be wrong with the QtCreator?
    Attached Images Attached Images
    Last edited by dajunior; 5th April 2015 at 21:09.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problems with MOC, vtable error

    vtable errors usually mean you added the Q_OBJECT macro to a header after adding the header to the project.
    Which means qmake did not yet see the macro and has not created a rule for running MOC on the classes declared in that header.

    You can just manually trigger a qmake run via the respective entry in the Build menu.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problems with MOC, vtable error

    Oh thank you, but I don't understand.
    Of course I added the header with no Q_OBJECT first. How could I know that I'd need it?
    Also I found another problem. I couldn't compile this line using QtCreator:
    QObject::connect(&MyCube, &cube::changed, MyCubeWidget, static_cast<void(CubeWidget::*)()>(&CubeWidget::up date));

    So I was forced to use old style:
    QObject::connect(&MyCube, SIGNAL(changed()), MyCubeWidget, SLOT(update()));

    But when I tried to compile my project manually using qmake and make I found that the first variant was okey. Why is it so? Why QtCreator acts so strange?
    I'm a bit disappointed with QtCreator honestly...
    Last edited by dajunior; 6th April 2015 at 07:10.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problems with MOC, vtable error

    Quote Originally Posted by dajunior View Post
    Oh thank you, but I don't understand.
    Of course I added the header with no Q_OBJECT first. How could I know that I'd need it?
    Well, the only reason not to add Q_OBJECT is that the class does not inherit QObject or a derived class.
    If the inheritance is changed later on, then the effect you've described can happen.

    Which, as I explained above, can be easily remidied by running qmake once.

    Quote Originally Posted by dajunior View Post
    Also I found another problem. I couldn't compile this line using QtCreator:
    QObject::connect(&MyCube, &cube::changed, MyCubeWidget, static_cast<void(CubeWidget::*)()>(&CubeWidget::up date));
    What was the error you were getting?
    Do you have overloaded update() functions, i.e. why is there a need for the cast?

    [QUOTE=dajunior;275337]
    But when I tried to compile my project manually using qmake and make I found that the first variant was okey.
    [/quote
    Are you running the same qmake?

    Cheers,
    _

Similar Threads

  1. undefined reference to vtable error
    By PaulDaviesC in forum Newbie
    Replies: 4
    Last Post: 20th April 2012, 16:11
  2. Replies: 3
    Last Post: 31st July 2011, 00:30
  3. no moc generated , vtable link error
    By eric_vi in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2010, 20:17
  4. vtable problems
    By high_flyer in forum Qt Programming
    Replies: 6
    Last Post: 3rd September 2007, 13:52
  5. Vtable linker error
    By jhearon in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 17:31

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.