【发布时间】:2018-08-04 16:42:07
【问题描述】:
尝试构建我直接从QT for beginners wiki page 复制粘贴的代码时出错。
错误
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Window::Window(class QWidget *)" (??0Window@@QEAA@PEAVQWidget@@@Z) referenced in function main
debug\testempty.exe:-1: error: LNK1120: 1 unresolved externals
testempty.pro
TEMPLATE = app
TARGET = testempty
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
main.cpp \
window.cpp
HEADERS += \
window.h
window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class QPushButton;
class Window : public QWidget
{
public:
explicit Window(QWidget *parent = nullptr);
private:
QPushButton *m_button;
};
#endif // WINDOW_H
window.cpp
#include "window.h"
#include <QPushButton>
Window::Window(QWidget *parent) : QWidget(parent)
{
setFixedSize(100, 50);
m_button = new QPushButton("Hello World", this);
m_button->setGeometry(10, 10, 80, 30);
}
main.cpp
#include <QApplication>
#include "window.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
至于我已经尝试过的事情,我被指示构建->清理所有并再次尝试构建,但这没有任何区别。
【问题讨论】:
-
首先,不要对错误进行截图,复制/粘贴。其次,您使用的是哪个版本的
Qt? -
Qt Creator 4.5.1(社区)
-
Qt 是否安装正确?哪个版本?你能在上面运行其他的吗?
-
我认为 QT 是 5.10.0 版。我已经成功地在上面构建了其他项目。