QT 如何包含头文件和 cpp 文件

QT how to include a header and cpp file

提问人:Zacharia Hildreth 提问时间:4/20/2018 更新时间:4/20/2018 访问量:1522

问:

我有一个qt项目,设置如下

mainwindow.h

main.cpp
mainwindow.cpp

在 mainwindow.h 中

just some function prototypes no includes

在主窗口.cpp

#include "mainwindow.h"
some code

在主.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    

谢谢

C++ Qt 链接器错误未 解决外部

评论

0赞 cmf41013 1/3/2020
对不起。.pro 文件后面或文件中的代码,为什么不在一行中?SOURCES +=HEADERS +=

答:

0赞 Zacharia Hildreth 4/20/2018 #1

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

评论

1赞 MrEricSir 4/21/2018
如果是这种情况,请将您的问题标记为重复问题。