Partage
  • Partager sur Facebook
  • Partager sur Twitter

[QT] PB undefined reference to !!!

    5 octobre 2007 à 2:31:47

    Salut

    J'ai écris un petit prog avec QT mais je sais l'erreur vienne d'où, le prog est divisé en trois fichiers :

    main.cpp

    1. #include <QApplication>
    2. #include "filedialog.h"
    3. int main(int argc, char *argv[])
    4. {
    5.     QApplication app(argc, argv);
    6.     FindDialog *dialog = new FindDialog;
    7.     dialog->show();
    8.     return app.exec();
    9. }



    filedialog.h

    1. #ifndef FINDDIALOG_H
    2. #define FINDDIALOG_H
    3. #include <QDialog>
    4. class QCheckBox;
    5. class QLabel;
    6. class QLineEdit;
    7. class QPushButton;
    8.  class FindDialog : public QDialog
    9.  {
    10.     Q_OBJECT
    11. public:
    12.     FindDialog(QWidget *parent = 0);
    13. signals:
    14.     void findNext(const QString &str, Qt::CaseSensitivity cs);
    15.     void findPrevious(const QString &str, Qt::CaseSensitivity cs);
    16. private slots:
    17.     void findClicked();
    18.     void enableFindButton(const QString &text);
    19. private:
    20.     QLabel *label;
    21.     QLineEdit *lineEdit;
    22.     QCheckBox *caseCheckBox;
    23.     QCheckBox *backwardCheckBox;
    24.     QPushButton *findButton;
    25.     QPushButton *closeButton;
    26. };
    27. #endif


    filedialog.cpp

    1. #include <QtGui>
    2. #include "filedialog.h"
    3. FindDialog::FindDialog(QWidget *parent)
    4.    : QDialog(parent)
    5. {
    6.     label = new QLabel(tr("Find &what:"));
    7.     lineEdit = new QLineEdit;
    8.     label->setBuddy(lineEdit);
    9.     caseCheckBox = new QCheckBox(tr("Match &case"));
    10.     backwardCheckBox = new QCheckBox(tr("Search &backward"));
    11.     findButton = new QPushButton(tr("&Find"));
    12.     findButton->setDefault(true);
    13.     findButton->setEnabled(false);
    14.     closeButton = new QPushButton(tr("Close"));
    15.     connect(lineEdit, SIGNAL(textChanged(const QString &)),
    16.             this, SLOT(enableFindButton(const QString &)));
    17.     connect(findButton, SIGNAL(clicked()),
    18.             this, SLOT(findClicked()));
    19.     connect(closeButton, SIGNAL(clicked()),
    20.             this, SLOT(close()));
    21.     QHBoxLayout *topLeftLayout = new QHBoxLayout;
    22.     topLeftLayout->addWidget(label);
    23.     topLeftLayout->addWidget(lineEdit);
    24.     QVBoxLayout *leftLayout = new QVBoxLayout;
    25.     leftLayout->addLayout(topLeftLayout);
    26.     leftLayout->addWidget(caseCheckBox);
    27.     leftLayout->addWidget(backwardCheckBox);
    28.     QVBoxLayout *rightLayout = new QVBoxLayout;
    29.     rightLayout->addWidget(findButton);
    30.     rightLayout->addWidget(closeButton);
    31.     rightLayout->addStretch();
    32.     QHBoxLayout *mainLayout = new QHBoxLayout;
    33.     mainLayout->addLayout(leftLayout);
    34.     mainLayout->addLayout(rightLayout);
    35.     setLayout(mainLayout);
    36.     setWindowTitle(tr("Find"));
    37.     setFixedHeight(sizeHint().height());
    38. }
    39. void FindDialog::findClicked()
    40. {
    41.     QString text = lineEdit->text();
    42.     Qt::CaseSensitivity cs =
    43.             caseCheckBox->isChecked() ? Qt::CaseSensitive
    44.                                       : Qt::CaseInsensitive;
    45.     if (backwardCheckBox->isChecked()) {
    46.         emit findPrevious(text, cs);
    47.     } else {
    48.         emit findNext(text, cs);
    49.     }
    50. }
    51. void FindDialog::enableFindButton(const QString &text)
    52. {
    53.     findButton->setEnabled(!text.isEmpty());
    54. }


    J'ai les erreurs suivantes :o

    1. :: === monQT2, Debug ===
    2. obj\Debug\filedialog.o:: In function `ZN10FindDialogC2EP7QWidget':D:/MyProjects/monQT2/filedialog.cpp:8: undefined reference to `vtable for FindDialog'
    3. :D:\MyProjects\monQT2\filedialog.cpp:8: undefined reference to `vtable for FindDialog'
    4. obj\Debug\filedialog.o:: In function `ZN10FindDialogC1EP7QWidget':D:/MyProjects/monQT2/filedialog.cpp:8: undefined reference to `vtable for FindDialog'
    5. :D:\MyProjects\monQT2\filedialog.cpp:8: undefined reference to `vtable for FindDialog'
    6. obj\Debug\filedialog.o:: In function `ZN10FindDialog11findClickedEv':D:/MyProjects/monQT2/filedialog.cpp:54: undefined reference to `FindDialog::findPrevious(QString const&, Qt::CaseSensitivity)'
    7. :D:\MyProjects\monQT2\filedialog.cpp:56: undefined reference to `FindDialog::findNext(QString const&, Qt::CaseSensitivity)'
    8. obj\Debug\filedialog.o:: In function `ZSt3minIjERKT_S2_S2_':D:/Qt/4.3.1/include/QtCore/../../src/corelib/tools/qstring.h:(.text$_ZN10FindDialog2trEPKcS1_[__ZN10FindDialog2trEPKcS1_]+0x1c): undefined reference to `FindDialog::staticMetaObject'
    9. :: === Build finished: 3 errors, 0 warnings ===


    PS : j'ai fait expret de ne pas mettre le code Autre sans colorations, et j'ai choisis le Bash :p

    merci de m'avoir répondre
    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      5 octobre 2007 à 7:48:13

      Recherche du côté de vtable, déjà traité pas mal de fois. ;)
      • Partager sur Facebook
      • Partager sur Twitter
        5 octobre 2007 à 17:06:15

        Merci pour le lien ;)

        Citation : doc

        Il vous suffira d'ajouter le fichier moc_****.cpp géneré à votre projet (il se trouve dans le même dossier que le fichier ****.h correspondant) et lors des prochaines compilations, tout se passera "normalement".



        Bah, ce fichier je le trouve ou ? :euh: je l'ai pas dans le dossier du projet o_O

        Citation : doc

        Pour Code::Blocks, allez dans "Project > Build Option", sélectionnez l'onglet "Commands".
        Dans le premier champ texte multi-ligne (Pre-Build Step), entrez la commande suivante :

        qt-moc-ui ****.h


        Si je fais ça, j'appuie sur F9 et me donne ce message :

        1. It seem that this project has not has not been built yet.
        2. Do you want to build it now ?


        Je clic sur Ok 36 fois mais il réapparaît encore et encore o_O , et si je clic sur Non rien ne se passe mais la compilation ne se déroule pas o_O

        • Partager sur Facebook
        • Partager sur Twitter
        Anonyme
          5 octobre 2007 à 17:52:27

          Ma technique est plus simple je trouve. (cf signature)
          • Partager sur Facebook
          • Partager sur Twitter

          [QT] PB undefined reference to !!!

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown