【问题标题】:missing symbols linking Qt 5.4 app缺少链接 Qt 5.4 应用程序的符号
【发布时间】:2015-07-07 01:12:25
【问题描述】:

嗯...我正在学习 Qt。我正在按照这本书迈出第一步:“C++ GUI Programming with Qt 4”。现在当我尝试编译我的代码时遇到问题。我在 Mac OS X Yosemite 10.10.4 中使用 Qt 5.4。我只收到 2 个错误::-1: error: symbol(s) not found for architecture x86_64, :-1: error: linker command failed with exit code 1(使用 -v 到查看调用)

这是我的 find.pro

#-------------------------------------------------
#
# Project created by QtCreator 2015-06-28T01:20:29
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET   = find

TEMPLATE = app

HEADERS  = finddialog.h

SOURCES  = finddialog.cpp \
                main.cpp

这是我的 finddialog.h

#ifndef FINDDIALOG_H
#define FINDDIALOG_H

#include <QDialog>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>

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

这是我的 finddialong.cpp

#include <QtGui>
#include <QApplication>
#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(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 *rigthLayout = new QVBoxLayout;
    rigthLayout->addWidget(findButton);
    rigthLayout->addWidget(closeButton);
    rigthLayout->addStretch();

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rigthLayout);
    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);
    }
}

这是我的 main.cpp

#include <QApplication>
#include "finddialog.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    FindDialog *dialog = new FindDialog;
    dialog->show();

    return app.exec();
}

输出是这样的

19:56:55: Running steps for project find...
19:56:55: Configuration unchanged, skipping qmake step.
19:56:55: Starting: "/usr/bin/make" 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/Applications/Qt/5.4/clang_64/lib -o find.app/Contents/MacOS/find finddialog.o main.o moc_finddialog.o   -F/Applications/Qt/5.4/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL 
Undefined symbols for architecture x86_64:
  "FindDialog::enableFindButton(QString const&)", referenced from:
      FindDialog::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) in moc_finddialog.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [find.app/Contents/MacOS/find] Error 1
19:56:58: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project find (kit: Desktop Qt 5.4.2 clang 64bit)
When executing step "Make"
19:56:58: Elapsed time: 00:03.

我希望你能帮助我我已经在网上寻找了几天的信息,但我无法解决问题。

【问题讨论】:

标签: macos qt osx-yosemite


【解决方案1】:

你应该定义槽

void enableFindButton(const QString &text);

或者如果你不使用它,就直接删除它。

您还应该删除前向声明

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

因为你已经包含了它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2010-12-17
    • 2015-02-10
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多