hello all,

I am trying to compile this canned example in QT4 , but the compiler spews out an error messagethat I have never seen before.

The *.cpp file:

#include <QtGui>

#include "finddialog.h"

FindDialog::FindDialog(QWidget *parent)
    : QDialog(parent)
{
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);

    caseCheckBox = new QCheckBox(tr("Match &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));

    findButton = new QPushButton(tr("&Find"));
    findButton->setDefault(true);
    findButton->setEnabled(false);

    closeButton = new QPushButton(tr("Close"));

    connect(lineEdit, SIGNAL(textChanged(const QString &)),
            this, SLOT(enableFindButton(const QString &)));
    connect(findButton, SIGNAL(clicked()),
            this, SLOT(findClicked()));
    connect(closeButton, SIGNAL(clicked()),
            this, SLOT(close()));

    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);
    topLeftLayout->addWidget(lineEdit);

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);
    leftLayout->addWidget(caseCheckBox);
    leftLayout->addWidget(backwardCheckBox);

    QVBoxLayout *rightLayout = new QVBoxLayout;
    rightLayout->addWidget(findButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);

    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
}

void FindDialog::findClicked()
{
    QString text = lineEdit->text();
    Qt::CaseSensitivity cs =
            caseCheckBox->isChecked() ? Qt::CaseSensitive
                                      : Qt::CaseInsensitive;
    if (backwardCheckBox->isChecked()) {
        emit findPrevious(text, cs);
    } else {
        emit findNext(text, cs);
    }
}

void FindDialog::enableFindButton(const QString &text)
{
    findButton->setEnabled(!text.isEmpty());
}

The header file;

#ifndef FINDDIALOG_H
#define FINDDIALOG_H

#include <QDialog>

class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;

class FindDialog : public QDialog
{
    Q_OBJECT

public:
    FindDialog(QWidget *parent = 0);

signals:
    void findNext(const QString &str, Qt::CaseSensitivity cs);
    void findPrevious(const QString &str, Qt::CaseSensitivity cs);

private slots:
    void findClicked();
    void enableFindButton(const QString &text);

private:
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
};

#endif

The compiler puke:

obj\Debug\finddialog.o:: In function `ZN10FindDialogC2EP7QWidget':
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:7: undefined reference to `vtable for FindDialog'
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:7: undefined reference to `vtable for FindDialog'
obj\Debug\finddialog.o:: In function `ZN10FindDialogC1EP7QWidget':
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:7: undefined reference to `vtable for FindDialog'
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:7: undefined reference to `vtable for FindDialog'
obj\Debug\finddialog.o:: In function `ZN10FindDialog11findClickedEv':
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:58: undefined reference to `FindDialog::findPrevious(QString const&, Qt::CaseSensitivity)'
C:\Documents and Settings\jim\My Documents\CB_projects\find\finddialog.cpp:60: undefined reference to `FindDialog::findNext(QString const&, Qt::CaseSensitivity)'
obj\Debug\finddialog.o:: In function `ZSt3minIjERKT_S2_S2_':
)]+0x1c):: undefined reference to `FindDialog::staticMetaObject'
:: === Build finished: 7 errors, 0 warnings ===

What baffles me is the distorted reference to the function
FindDialog::FindDialog(QWidget *parent) : QDialog(parent)
which comes out as `ZN10FindDialogC2EP7QWidget': in the compiler output.
What is this telling me?

Also I understand that vtable refers to the use of virtual functions, but I don't see any virtual declarations anywhere.

Does all this simply mean that it cant find QDialog???

Recommended Answers

All 5 Replies

ZN10FindDialogC2EP7QWidget is the result of the c++ compiler embedding type/namespace information in names (this is called name decoration or name mangling) . see: http://en.wikipedia.org/wiki/Name_mangling#Complex_example for an example.

you have probably inherited virtual functions from the base class QDialog

and i think you are not linking to the library that contains the (compiled) code for QDialog.
the c++ compiler would have demangled the name for you in a diagnostic; the error is from ld
check it out by first just compiling your cpp file ( -c ); it should compile ok if your headers are right

http://en.wikipedia.org/wiki/Name_mangling#Complex_example for an example.

you have probably inherited virtual functions from the base class QDialog

and i think you are not linking to the library that contains the (compiled) code for QDialog.
the c++ compiler would have demangled the name for you in a diagnostic; the error is from ld
check it out by first just compiling your cpp file ( -c ); it should compile ok if your headers are right

Thanks for the URL on this. You are also correct about it being a linker issue. The question is what to do about it? i found the QDialog file buried in a sub directory of include. I entered the path in the search path for the linker, but still no good results. Also when I look at the QDialog file under properties, it is only recognized as a 'file" -not cpp or application. I tend to believe that it must be a *.cpp since there is a *.h sitting right next to it with the same name.

I'm a bit over my head with all this stuff, but that's how i learn.
Any further insight would be appreciated.

QDialog is a header file (header files in qt 4.3 do not have a .h extension; they are like headers in libstdc++ ( <iostream>, <QDialog> ).

the easiest way to build a qt applicatiom is to create a Makefile using qmake.
here is a link to a simple tutorial to get you started: http://doc.trolltech.com/4.3/qmake-tutorial.html#starting-off-simple

then just run make (unix) from the same directory where you created the Makefile [ or gmake (linux) or nmake (microsoft) ]. qmake would have created a Makefile which sets up the build enviroinment (compiler switches, library paths etc.) for qt correctly. that is all you would require for this simple example.

QDialog is a header file (header files in qt 4.3 do not have a .h extension; they are like headers in libstdc++ ( <iostream>, <QDialog> ).

the easiest way to build a qt application is to create a Makefile using qmake.

Actually, I'm using Codeblocks IDE which has a project wizard for QT4.
I have compiled (and linked) other Qt4 (version 4.1.1) projects successfully, but this is the first one that required <Qdialog> . I just don't know what else I can do to make it work. The linker continues to complain while the object files are there ready to go...
so close...yet so far away...

Is Qt generally this clunky? would I be better off with Wxwidgets or the "new guy" OMGUI? I'm going to have it hard enough writing the code without having to fight the linker too!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.