Ich wollte mal mit der GUI-Programmierung weitermachen und habe mich entschieden, mit Hilfe des Buches "C++ GUI Programming with Qt 4
By Jasmin Blanchette, Mark Summerfield" meine Kenntnisse zu verbessern.
Eines der ersten Beispiele im Buch ist ein "Suchfenster". Den Code habe ich garantiert richtig abgetippt. Hier ist er nochmal zur Kontrolle:
main.cc
Code: Alles auswählen
#include <QApplication>
#include "FindDialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FindDialog dia1;
dia1.show();
return app.exec();
}
Code: Alles auswählen
#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 // FindDialog_H
Code: Alles auswählen
#include <QtGui>
#include <QDialog>
#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());
}
Code: Alles auswählen
SOURCES += main.cc \
FindDialog.cpp
HEADERS += FindDialog.h
Code: Alles auswählen
PFAD/Qt/16-07-09-Practise/debug/moc_FindDialog.cpp:76: undefined reference to `FindDialog::findClicked()'
PFAD/Qt/16-07-09-Practise/debug/moc_FindDialog.cpp:77: undefined reference to `FindDialog::enableFindButton(QString const&)'
:-1: error: collect2: ld returned 1 exit status
Woran könnte das liegen, und was soll ich machen?
Vielen Dank für eure Hilfe!
Gruß,
Milten