首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少连接QT5.4应用程序的符号

缺少连接QT5.4应用程序的符号
EN

Stack Overflow用户
提问于 2015-07-07 01:12:25
回答 1查看 225关注 0票数 0

好吧..。我在学Qt。我正在按照这本书做我的第一步:“使用Qt4进行C++ GUI编程”。现在,当我试图编译代码时,我遇到了问题。我在10.10.4中使用QT5.4。我只得到两个错误::-1:错误:在体系结构x86_64中找不到符号,:-1:错误:链接器命令失败,退出代码1(使用-v查看调用)

这是我的find.pro

代码语言:javascript
复制
#-------------------------------------------------
#
# 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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#include <QApplication>
#include "finddialog.h"

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

    return app.exec();
}

输出如下

代码语言:javascript
复制
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.

嗯,我希望你能帮我,我已经在网上找了好几天的信息了,但我解决不了这个问题。

EN

回答 1

Stack Overflow用户

发布于 2015-07-07 01:27:57

你应该定义插槽

代码语言:javascript
复制
void enableFindButton(const QString &text);

或者,如果您不使用声明,则只需删除它。

您还应该删除前向声明。

代码语言:javascript
复制
class QCheckBox; 
class QLabel; 
class QLineEdit; 
class QPushButton;

因为你已经把它们包括进去了

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31258193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档