2016-06-12 107 views
-2

好吧,花30分鐘左右看看這個問題的常見原因,我看不出有什麼問題。在qt項目中無法解析的外部符號

我得到的錯誤是無法解析的外部符號。有問題的符號是一個名爲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中添加新的類來補充它,並且添加頁眉和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 

終於在主窗口.cpp裏我創建一個AdventureDocs對象是我得到錯誤的地方。

#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; 
} 

有人可以指出明顯的出血,我明顯失蹤謝謝。

+0

你究竟得到哪個錯誤? – Murphy

+1

這是一個無法解析的外部符號錯誤,但我已經整理出來了。就像我說的那樣,出血很明顯,自從添加文件後,我沒有重新運行qmake。 – user2801678

回答

0

現在整理出來。我是愚蠢的,沒有重新運行qmake