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
source share