gpt4 book ai didi

c++ - Qtcreator 将小部件提升到该类后找不到类头文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:08 29 4
gpt4 key购买 nike

我是 Qt 的新手,对 C++ 也不是很熟悉。

我创建了简单的 Qt GUI 应用程序,但后来我不得不在 QLabel 类型的对象上添加 mousepressevent 函数,所以我创建了具有头文件的类以下代码:

#ifndef IMAGEACTION_H
#define IMAGEACTION_H

#include <QLabel>
#include <QMouseEvent>
#include <QDebug>
#include <QEvent>

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:无法打开包含文件:'imageaction.h':没有这样的文件或目录

你能说说我错在哪里吗?为了制作这门课,我遵循了这个 video

最佳答案

我认为,“C1083:无法打开包含文件:'imageaction.h':没有这样的文件或目录”错误来自您的 ui_*.h 文件。如果是这种情况,那么您的问题是关于推广 imageaction 小部件。

This may work
1. while promoting imageaction widget, uncheck "globalinclude".
or
2. Update pro file with "INCLUDEPATH += path where mywidget.h"

更多信息请查看Promoting Widget

关于c++ - Qtcreator 将小部件提升到该类后找不到类头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18471827/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com