I'm a newbie in Qt and not that much experienced in C++ either.
I created simple Qt GUI app, but then I had to add the mousepressevent
function on a QLabel
type object, so I created the class which has the header file with 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();
}
In the mainwindow.cpp
file added the line #include "imageaction.h"
to include the header file and in the .pro
file it's the following lines are also added:
SOURCES += main.cpp\
mainwindow.cpp \
imageaction.cpp
HEADERS += mainwindow.h \
imageaction.h
But the program always gives the following error:
C1083: Cannot open include file:'imageaction.h': No such file or directory
.
Could you say where I'm making the mistake? To make this class I followed this video
I think, "C1083: Cannot open include file:'imageaction.h': No such file or directory" error from your ui_*.h file. If that is the case, your issue regading promoting 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 for more info Promoting Widget
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With