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

时间:2018-04-20 15:39:35

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

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

标题

mainwindow.h

main.cpp
mainwindow.cpp
主窗口中的

just some function prototypes no includes
在mainwindow.cpp

#include "mainwindow.h"
some code

在main.cpp

#include "mainwindow.h"

这似乎有效,是qt IDE如何设置程序

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

animationfunctions.h

#ifndef ANIMATIONFUNCTIONS_H
#define ANIMATIONFUNCTIONS_H

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

#endif // ANIMATIONFUNCTIONS_H

animationfunctions.cpp

#include "animationfunctions.h"

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

mainwindow.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    

由于

1 个答案:

答案 0 :(得分:0)

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

相关问题