qt项目中未解析的外部符号[重复]

Unresolved external symbol in qt project [duplicate]

提问人:user2801678 提问时间:6/12/2016 更新时间:6/12/2016 访问量:751

问:

好的,所以花 30 分钟左右的时间看看这个问题的常见原因,我看不出出有什么问题。

我得到的错误是未解析的外部符号。有问题的符号是一个名为 AdventureDocs 的类。标题如下。

#ifndef ADVENTUREDOCS_H
#define ADVENTUREDOCS_H

#include <QWidget>

class AdventureDocs : public QWidget
{
    Q_OBJECT
public:
    AdventureDocs(QObject *parent);
};

#endif // ADVENTUREDOCS_H

和CPP

#include "adventuredocs.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QTabWidget>

AdventureDocs::AdventureDocs(QObject *parent): QWidget(parent)
{
    QHBoxLayout *hLayout = 0;
    QVBoxLayout *vLayout = 0;
    QPushButton *button = 0;
    QLabel *label = 0;

    hLayout = new QHBoxLayout();
    Q_ASSERT(hLayout);

    vLayout = new QVBoxLayout();
    Q_ASSERT(vLayout);

    // Set the layout to the widget
    setLayout(hLayout);
    hLayout->addLayout(vLayout);

    // Draw widgets on main page.
    label = new QLabel(hLayout);
    Q_ASSERT(label);
    hLayout->addWidget(label);

    label->setText("Adventure Docs");
}

这是一个类,而不是库或任何智能的东西,例如我在 qt creator 中使用 add new class 来添加它,并将标头和 cpp 添加到项目文件中,如下所示。

#-------------------------------------------------
#
# Project created by QtCreator 2016-06-12T11:06:47
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = AdventureDocs
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    adventuredocs.cpp

HEADERS  += mainwindow.h \
    adventuredocs.h

FORMS    += mainwindow.ui

最后,在我创建 AdventureDocs 对象的主窗口.cpp中,我得到了错误。

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include "adventuredocs.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    AdventureDocs *main = 0;

    main =  new AdventureDocs(this);
    if (main != 0)
    {
        setCentralWidget(main);
    }
}

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

有人可以指出我显然错过的明显出血吗,谢谢。

C++ Qt 未解析外部

评论

0赞 Murphy 6/12/2016
你到底得到了哪个错误?
1赞 user2801678 6/12/2016
这是一个未解决的外部符号错误,但我现在已经解决了。就像我说的,很明显,自从添加文件以来,我没有重新运行 qmake。

答:

0赞 user2801678 6/12/2016 #1

现在整理出来了。是我傻了,没有重新运行 qmake