我是 Qt 的新手,在 C++ 方面也没有多少经验。
我创建了简单的 Qt GUI 应用程序,但后来我不得不mousepressevent在类型对象上添加函数QLabel,所以我创建了具有以下代码的头文件的类:
#ifndef IMAGEACTION_H
#define IMAGEACTION_H
#include
#include
#include
#include
class imageaction : public QLabel
{
Q_OBJECT
public:
explicit imageaction(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *ev);
signals:
void Mouse_Pressed();
public slots:
};
#endif // IMAGEACTION_H
该.cpp文件具有以下代码:
#include "imageaction.h"
imageaction::imageaction(QWidget *parent) :
QLabel(parent)
{
}
void imageaction::mousePressEvent(QMouseEvent *ev)
{
emit Mouse_Pressed();
}
在mainwindow.cpp文件中添加了#include "imageaction.h"包含头文件的行,并且在.pro文件中还添加了以下行:
SOURCES += main.cpp\
mainwindow.cpp \
imageaction.cpp
HEADERS += mainwindow.h \
imageaction.h
但是程序总是给出以下错误:
C1083: Cannot open include file:'imageaction.h': No such file or directory.
你能说我在哪里犯了错误吗?为了制作这门课,我关注了这个视频