-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
とこのクラスではない、私はそれを追加するQTクリエーターに新しいクラスを追加使用していると、そのプロジェクトにヘッダーと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");
}
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;
}
誰かが明らかに出血を指摘することができますか?
そして、どのエラーが発生しますか? – Murphy
未解決の外部シンボルエラーでしたが、私は今すぐソートしました。私はそれが明らかに出血していると言ったように、私はファイルを追加してからqmakeを再実行しませんでした。 – user2801678