【问题标题】:QT how to include a header and cpp fileQT如何包含头文件和cpp文件
【发布时间】:2018-10-01 09:15:31
【问题描述】:

我有一个像这样设置的 qt 项目

标题

mainwindow.h

来源

main.cpp
mainwindow.cpp

在 mainwindow.h 中

just some function prototypes no includes

在 mainwindow.cpp 中

#include "mainwindow.h"
some code

在main.cpp中

#include "mainwindow.h"

这似乎可行,这就是 qt IDE 设置程序的方式

现在我想为某些功能添加单独的 .h 和 .cpp 程序

动画函数.h

#ifndef ANIMATIONFUNCTIONS_H
#define ANIMATIONFUNCTIONS_H

QPropertyAnimation* animationbuttonleft(QPushButton* guiitem, QString location, int startposition);

#endif // ANIMATIONFUNCTIONS_H

动画函数.cpp

#include "animationfunctions.h"

QPropertyAnimation* animationbuttonleft(QPushButton* guiitem, QString location, int startposition)
{
//
}

主窗口.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "animationfunctions.h"

我认为这会起作用,但它没有。我尝试了很多不同的包含组合,但我总是得到一个 lnk 2019 错误,QPropertyAnimation* animationbuttonleft 的外部符号未解析

我想知道我应该如何设置它?

这是我的 .pro 文件的相关部分

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

HEADERS += \
        mainwindow.h \
    xcash_wallet_2.rc \
    animationfunctions.h    

谢谢

【问题讨论】:

  • 对不起。 .pro文件中SOURCES +=HEADERS +=后面的代码,为什么不在一行?

标签: c++ qt linker-errors unresolved-external


【解决方案1】:

我从另一个堆栈溢出中发现,您只需清理您的项目,然后从构建选项卡运行 qmake。

【讨论】:

  • 如果是这种情况,请将您的问题标记为重复。
猜你喜欢
  • 2014-01-04
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
相关资源
最近更新 更多