链接Qt 5.4 app的缺失符号

时间:2015-07-07 01:12:25

标签: macos qt osx-yosemite

嗯......我正在学习Qt。我正在按照本书开始我的第一个步骤:“使用Qt 4进行C ++ GUI编程”。现在,当我尝试编译代码时,我遇到了问题。我在Mac OS X Yosemite 10.10.4中使用Qt 5.4。我只得到2个错误:: - 1:错误:找不到架构x86_64的符号: - 1:错误:链接器命令失败,退出代码为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.

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

1 个答案:

答案 0 :(得分:3)

您应该定义插槽

var data = {clients:[{firstName:"Donald", lastName:"Duck"}]};
...// create and set model here
var oLabel = new sap.ui.commons.Label("myLabel");
oLabel.bindProperty("text", "firstName");
oLabel.bindElement("/clients/0");

如果你不使用它,只需删除声明即可。

您还应该删除前向声明

void enableFindButton(const QString &text);

因为你已经包含了它们