IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

undefined reference to `vtable for


Sujet :

Qt

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    433
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 433
    Points : 112
    Points
    112
    Par défaut undefined reference to `vtable for
    Salut,

    j'ai récupéré le code des exemples de QT4.5
    voici le lien

    au fait un message d'erreur que j'arrive pas à comprendre

    C:\Projet\Projet\Tetrixboard.cpp|5|undefined reference to `vtable for TetrixBoard'|

    Voila mon fichier TetrixBoard.cpp


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    #include <QtGui>
    #include "tetrixboard.h"
     
     TetrixBoard::TetrixBoard(QWidget *parent): QFrame(parent)
     {
         setFrameStyle(QFrame::Panel | QFrame::Sunken);
         setFocusPolicy(Qt::StrongFocus);
         isStarted = false;
         isPaused = false;
         clearBoard();
         nextPiece.setRandomShape();
     }
     
     void TetrixBoard::setNextPieceLabel(QLabel *label)
     {
         nextPieceLabel = label;
     }
     
     QSize TetrixBoard::sizeHint() const
     {
         return QSize(BoardWidth * 15 + frameWidth() * 2,
                      BoardHeight * 15 + frameWidth() * 2);
     }
     
     QSize TetrixBoard::minimumSizeHint() const
     {
         return QSize(BoardWidth * 5 + frameWidth() * 2,
                      BoardHeight * 5 + frameWidth() * 2);
     }
     
     void TetrixBoard::start()
     {
         if (isPaused)
             return;
     
         isStarted = true;
         isWaitingAfterLine = false;
         numLinesRemoved = 0;
         numPiecesDropped = 0;
         score = 0;
         level = 1;
         clearBoard();
     
         emit linesRemovedChanged(numLinesRemoved);
         emit scoreChanged(score);
         emit levelChanged(level);
     
         newPiece();
         timer.start(timeoutTime(), this);
     }
     
     void TetrixBoard::pause()
     {
         if (!isStarted)
             return;
     
         isPaused = !isPaused;
         if (isPaused) {
             timer.stop();
         } else {
             timer.start(timeoutTime(), this);
         }
         update();
     }
     
     void TetrixBoard::paintEvent(QPaintEvent *event)
     {
         QFrame::paintEvent(event);
     
         QPainter painter(this);
         QRect rect = contentsRect();
     
         if (isPaused) {
             painter.drawText(rect, Qt::AlignCenter, tr("Pause"));
             return;
         }
     
         int boardTop = rect.bottom() - BoardHeight*squareHeight();
     
         for (int i = 0; i < BoardHeight; ++i) {
             for (int j = 0; j < BoardWidth; ++j) {
                 TetrixShape shape = shapeAt(j, BoardHeight - i - 1);
                 if (shape != NoShape)
                     drawSquare(painter, rect.left() + j * squareWidth(),
                                boardTop + i * squareHeight(), shape);
             }
         }
     
         if (curPiece.shape() != NoShape) {
             for (int i = 0; i < 4; ++i) {
                 int x = curX + curPiece.x(i);
                 int y = curY - curPiece.y(i);
                 drawSquare(painter, rect.left() + x * squareWidth(),
                            boardTop + (BoardHeight - y - 1) * squareHeight(),
                            curPiece.shape());
             }
         }
     }
     
     void TetrixBoard::keyPressEvent(QKeyEvent *event)
     {
         if (!isStarted || isPaused || curPiece.shape() == NoShape) {
             QFrame::keyPressEvent(event);
             return;
         }
     
         switch (event->key()) {
         case Qt::Key_Left:
             tryMove(curPiece, curX - 1, curY);
             break;
         case Qt::Key_Right:
             tryMove(curPiece, curX + 1, curY);
             break;
         case Qt::Key_Down:
             tryMove(curPiece.rotatedRight(), curX, curY);
             break;
         case Qt::Key_Up:
             tryMove(curPiece.rotatedLeft(), curX, curY);
             break;
         case Qt::Key_Space:
             dropDown();
             break;
         case Qt::Key_D:
             oneLineDown();
             break;
         default:
             QFrame::keyPressEvent(event);
         }
     }
     
     void TetrixBoard::timerEvent(QTimerEvent *event)
     {
         if (event->timerId() == timer.timerId()) {
             if (isWaitingAfterLine) {
                 isWaitingAfterLine = false;
                 newPiece();
                 timer.start(timeoutTime(), this);
             } else {
                 oneLineDown();
             }
         } else {
             QFrame::timerEvent(event);
         }
     }
     
     void TetrixBoard::clearBoard()
     {
         for (int i = 0; i < BoardHeight * BoardWidth; ++i)
             board[i] = NoShape;
     }
     
     void TetrixBoard::dropDown()
     {
         int dropHeight = 0;
         int newY = curY;
         while (newY > 0) {
             if (!tryMove(curPiece, curX, newY - 1))
                 break;
             --newY;
             ++dropHeight;
         }
         pieceDropped(dropHeight);
     }
     
     void TetrixBoard::oneLineDown()
     {
         if (!tryMove(curPiece, curX, curY - 1))
             pieceDropped(0);
     }
     
     void TetrixBoard::pieceDropped(int dropHeight)
     {
         for (int i = 0; i < 4; ++i) {
             int x = curX + curPiece.x(i);
             int y = curY - curPiece.y(i);
             shapeAt(x, y) = curPiece.shape();
         }
     
         ++numPiecesDropped;
         if (numPiecesDropped % 25 == 0) {
             ++level;
             timer.start(timeoutTime(), this);
             emit levelChanged(level);
         }
     
         score += dropHeight + 7;
         emit scoreChanged(score);
         removeFullLines();
     
         if (!isWaitingAfterLine)
             newPiece();
     }
     
     void TetrixBoard::removeFullLines()
     {
         int numFullLines = 0;
     
         for (int i = BoardHeight - 1; i >= 0; --i) {
             bool lineIsFull = true;
     
             for (int j = 0; j < BoardWidth; ++j) {
                 if (shapeAt(j, i) == NoShape) {
                     lineIsFull = false;
                     break;
                 }
             }
     
             if (lineIsFull) {
                 ++numFullLines;
                 for (int k = i; k < BoardHeight - 1; ++k) {
                     for (int j = 0; j < BoardWidth; ++j)
                         shapeAt(j, k) = shapeAt(j, k + 1);
                 }
                 for (int j = 0; j < BoardWidth; ++j)
                     shapeAt(j, BoardHeight - 1) = NoShape;
             }
         }
     
         if (numFullLines > 0) {
             numLinesRemoved += numFullLines;
             score += 10 * numFullLines;
             emit linesRemovedChanged(numLinesRemoved);
             emit scoreChanged(score);
     
             timer.start(500, this);
             isWaitingAfterLine = true;
             curPiece.setShape(NoShape);
             update();
         }
     }
     
     void TetrixBoard::newPiece()
     {
         curPiece = nextPiece;
         nextPiece.setRandomShape();
         showNextPiece();
         curX = BoardWidth / 2 + 1;
         curY = BoardHeight - 1 + curPiece.minY();
     
         if (!tryMove(curPiece, curX, curY)) {
             curPiece.setShape(NoShape);
             timer.stop();
             isStarted = false;
         }
     }
     
     void TetrixBoard::showNextPiece()
     {
         if (!nextPieceLabel)
             return;
     
         int dx = nextPiece.maxX() - nextPiece.minX() + 1;
         int dy = nextPiece.maxY() - nextPiece.minY() + 1;
     
         QPixmap pixmap(dx * squareWidth(), dy * squareHeight());
         QPainter painter(&pixmap);
         painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background());
     
         for (int i = 0; i < 4; ++i) {
             int x = nextPiece.x(i) - nextPiece.minX();
             int y = nextPiece.y(i) - nextPiece.minY();
             drawSquare(painter, x * squareWidth(), y * squareHeight(),
                        nextPiece.shape());
         }
         nextPieceLabel->setPixmap(pixmap);
     }
     
     bool TetrixBoard::tryMove(const TetrixPiece &newPiece, int newX, int newY)
     {
         for (int i = 0; i < 4; ++i) {
             int x = newX + newPiece.x(i);
             int y = newY - newPiece.y(i);
             if (x < 0 || x >= BoardWidth || y < 0 || y >= BoardHeight)
                 return false;
             if (shapeAt(x, y) != NoShape)
                 return false;
         }
     
         curPiece = newPiece;
         curX = newX;
         curY = newY;
         update();
         return true;
     }
     
     void TetrixBoard::drawSquare(QPainter &painter, int x, int y, TetrixShape shape)
     {
         static const QRgb colorTable[8] = {
             0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
             0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00
         };
     
         QColor color = colorTable[int(shape)];
         painter.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2,
                          color);
     
         painter.setPen(color.light());
         painter.drawLine(x, y + squareHeight() - 1, x, y);
         painter.drawLine(x, y, x + squareWidth() - 1, y);
     
         painter.setPen(color.dark());
         painter.drawLine(x + 1, y + squareHeight() - 1,
                          x + squareWidth() - 1, y + squareHeight() - 1);
         painter.drawLine(x + squareWidth() - 1, y + squareHeight() - 1,
                          x + squareWidth() - 1, y + 1);
     }
    et mon fichier tetrixboard.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     
    #ifndef TETRIXBOARD_H
     #define TETRIXBOARD_H
     #include <C:\Qt1\4.5.1\include\QT\qbasictimer.h>
     #include <QFrame>
     #include <C:\Qt1\4.5.1\include\QT\qpointer.h>
     #include "tetrixpiece.h"
     
     class QLabel;
     
     class TetrixBoard : public QFrame
     {
         Q_OBJECT
     
     public:
         TetrixBoard(QWidget *parent = 0);
     
         void setNextPieceLabel(QLabel *label);
         QSize sizeHint() const;
         QSize minimumSizeHint() const;
     
     public slots:
         void start();
         void pause();
     
     signals:
         void scoreChanged(int score);
         void levelChanged(int level);
         void linesRemovedChanged(int numLines);
     
     protected:
         void paintEvent(QPaintEvent *event);
         void keyPressEvent(QKeyEvent *event);
         void timerEvent(QTimerEvent *event);
     
     private:
         enum { BoardWidth = 10, BoardHeight = 22 };
     
         TetrixShape &shapeAt(int x, int y) { return board[(y * BoardWidth) + x]; }
         int timeoutTime() { return 1000 / (1 + level); }
         int squareWidth() { return contentsRect().width() / BoardWidth; }
         int squareHeight() { return contentsRect().height() / BoardHeight; }
         void clearBoard();
         void dropDown();
         void oneLineDown();
         void pieceDropped(int dropHeight);
         void removeFullLines();
         void newPiece();
         void showNextPiece();
         bool tryMove(const TetrixPiece &newPiece, int newX, int newY);
         void drawSquare(QPainter &painter, int x, int y, TetrixShape shape);
     
         QBasicTimer timer;
         QPointer<QLabel> nextPieceLabel;
         bool isStarted;
         bool isPaused;
         bool isWaitingAfterLine;
         TetrixPiece curPiece;
         TetrixPiece nextPiece;
         int curX;
         int curY;
         int numLinesRemoved;
         int numPiecesDropped;
         int score;
         int level;
         TetrixShape board[BoardWidth * BoardHeight];
     };
     
     #endif
    des idées????
    merci d'avance

  2. #2
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    comment as tu compilé?
    Cette erreur viens d'un fichier auto généré par moc, qui na pas été ajouté lors de la compilation lors du link.

  3. #3
    Membre actif Avatar de gassi64
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2008
    Messages
    255
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juin 2008
    Messages : 255
    Points : 230
    Points
    230
    Par défaut
    moi je dirai qu'il manque un virtual quelque part...dans le .h
    peut être le destructeur ou autre chose

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    433
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 433
    Points : 112
    Points
    112
    Par défaut
    j'utilise code::block comme IDE, donc pour compiler cltr+F9.

    je sais pas comment ajouter dun fichier auto généré par moc.

    des idées????

  5. #5
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    Si tu utilise C::B, le plus simple est d'utiliser qmake pour générer les makefile à partir d'un .pro et d'utiliser ces makefile par C::B

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    433
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 433
    Points : 112
    Points
    112
    Par défaut
    stp tu peux détailler un peu plus je suis débutant en C++ et surtout QT4.5 et code::blocks
    merci d'avance

  7. #7
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    Citation Envoyé par zalalus Voir le message
    stp tu peux détailler un peu plus je suis débutant en C++ et surtout QT4.5 et code::blocks
    merci d'avance
    As tu regardé les tuto pour débutant?
    http://qt.developpez.com/tutoriels/introduction-qt/
    Il explique le .pro et qmake.
    Pour utiliser le makefile dans C::B, je ne sais pas. Je ne l'utilise pas.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    433
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 433
    Points : 112
    Points
    112
    Par défaut
    j'ai essayé le qmake mais j'ai toujours le même message d'erreur

    des idées????????????????

  9. #9
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    ta fait un .pro?
    Aprés le qmake, tu as fait un make pour tester sans C::B ?

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    433
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 433
    Points : 112
    Points
    112
    Par défaut
    oui, la dernière ligne
    mingw32-make:**** [Debug]Error2

  11. #11
    Membre actif Avatar de gassi64
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2008
    Messages
    255
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juin 2008
    Messages : 255
    Points : 230
    Points
    230
    Par défaut
    Utilise QtCreator fournit dans le dernier SDK de Qt

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    106
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 106
    Points : 74
    Points
    74
    Par défaut
    bonjour moi je suis dans le meme souci que toi et je compile aussi avec C::B si tu trouve la solution fait nous profitez .
    Merci .

  13. #13
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 033
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 033
    Points : 13 968
    Points
    13 968
    Par défaut
    Citation Envoyé par zalalus Voir le message
    oui, la dernière ligne
    mingw32-make:**** [Debug]Error2
    tu utilise l'invite de commande Qt?

    J'ai du mal à comprend ce que tu fait et ce qui ne marche.
    Normalement, si tu as un .pro,
    un qmake puis un make suffit.
    Si tu utilise C::B tu lui fait utiliser les makefile généré par qmake.

  14. #14
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 31
    Points : 12
    Points
    12
    Par défaut
    Peut-être as-tu trouvé la solution mais sinon, jette un coup d'oeil sur ce site, je pense que ton problème vient de là.
    Si tu n'as pas ajouter ton fichier moc, tu auras toujours cette erreur.

    http://webmail.appert44.org/~plegal/...c_Code::Blocks

    Bon courage!

Discussions similaires

  1. [Error] undefined reference to `vtable for ?
    Par Some0ne dans le forum C++
    Réponses: 1
    Dernier message: 20/01/2011, 00h34
  2. Réponses: 13
    Dernier message: 17/05/2010, 21h28
  3. Réponses: 1
    Dernier message: 19/07/2009, 22h37
  4. undefined reference to `vtable for Graphique'
    Par lilly91 dans le forum Débuter
    Réponses: 11
    Dernier message: 23/06/2009, 17h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo