Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qtcreator can't find the class header file after promoting a widget to that class?

Tags:

c++

qt

qt-creator

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

like image 809
the_naive Avatar asked Mar 22 '23 15:03

the_naive


1 Answers

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

like image 67
Ashif Avatar answered Apr 25 '23 09:04

Ashif