2015-07-07 2 views
0

Ну ... Я изучаю Qt. Я делаю первые шаги своего ребенка после этой книги: «C++ GUI Programming with Qt 4». Теперь у меня проблемы, когда я пытаюсь скомпилировать свой код. Я использую Qt 5.4 в Mac OS X Yosemite 10.10.4. Я просто получить 2 ошибки: : -1: ошибка: символ (ы) не найдено для архитектуры x86_64, : -1: ошибка: команда линкер потерпела неудачу с кодом выхода 1 (использование -v, чтобы увидеть вызова)Отсутствующие символы, связывающие Qt 5.4 app

это мой 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. 

Ну, я надеюсь, что вы можете мне помочь, я искал информацию в Интернете по несколько дней и я не мог решить проблему.

+0

возможный дубликат [ "Символ (ы) не найдено для архитектуры x86 \ _64" по проекту QtCreator] (HTTP://stackoverflow.com/questions/18973042/symbols-not-found-for-architecture-x86-64-on-qtcreator-project) – TheDarkKnight

ответ

3

Вы должны определить слот для

void enableFindButton(const QString &text); 

Или просто удалить объявление, если вы не используете его.

Вы также должны удалить вперед заявления

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

, так как вы уже включили их

Смежные вопросы