qt 초급 오류: 헤더 파일에서 정의, cpp가 실행되지 않았습니다.

2790 단어 QT

오류 정보


문제


:-1: error: symbol(s) not found for architecture x86_64 :-1: error: linker command failed with exit code 1 (use -v to see invocation)

컴파일 출력


Undefined symbols for architecture x86_64: “MainWindow::slotQuestion()”, referenced from: MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) in moc_mainwindow.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: * [Hello2.app/Contents/MacOS/Hello2] Error 1 22:39:31: 프로세스'/usr/bin/make'를 종료하고 코드 2를 종료합니다.Error while building/deploying project Hello2 (kit: Desktop Qt 5.5.1 clang 64bit) When executing step “Make”

원인


헤더 파일에 정의된slot이 cpp에서 실행되지 않아 컴파일 오류가 발생했습니다.

코드


오류 코드


mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include 

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
private slots:
    void slotQuestion();
};

#endif // MAINWINDOW_H

mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setWindowTitle(tr("HelloQt"));
    connect(btn1,SIGNAL(clicked(bool)),this,SLOT(slotQuestion()));

}

MainWindow::~MainWindow()
{
    delete ui;
}

수정하다


메인 창에서만 가능합니다.cpp에 slot을 실현하면 ok입니다void MainWindow::slotQuestion()
{
}

좋은 웹페이지 즐겨찾기