Qtcreator cannot find the class header file after moving the widget to this class?

I am new to Qt and not much experienced in C ++.

I created a simple Qt GUI application, but then I had to add a mousepressevent function to an object of type QLabel , so I created a class that has a header file with the following code:

 #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 

The .cpp file has the following code:

 #include "imageaction.h" imageaction::imageaction(QWidget *parent) : QLabel(parent) { } void imageaction::mousePressEvent(QMouseEvent *ev) { emit Mouse_Pressed(); } 

The #include "imageaction.h" line was added to the mainwindow.cpp file to include the header file, and the following lines were added to the .pro file:

 SOURCES += main.cpp\ mainwindow.cpp \ imageaction.cpp HEADERS += mainwindow.h \ imageaction.h 

But the program always produces the following error:

C1083: Cannot open include file:'imageaction.h': No such file or directory .

Could you tell me where I am making a mistake? To make this class I watched this video

+4
source share
1 answer

I think, "C1083: I can not open the include: imageaction.h: There is no such file or directory" file from your ui _ * file. h. If so, your problem is with the promotion of the imageaction widget.

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

Please check additional information. Promotion widget

+6
source

Source: https://habr.com/ru/post/1499201/


All Articles