the_naive
the_naive

Reputation: 3064

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

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

Upvotes: 6

Views: 7306

Answers (3)

Caio Tavares
Caio Tavares

Reputation: 11

The problem it's just your path in cmake, so just put this code in your CMakeLists.txt: target_include_directories(<YOUR PROJECT NAME> PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

Upvotes: 0

Fahad Hasan Pathik
Fahad Hasan Pathik

Reputation: 406

For CMake, it needs to have include directory paths to work with. In CMakeLists this can be done by include directory directives. For Example:

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

If the header files are in separate include folder then this should be written in CMakeLists:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

Upvotes: 12

Ashif
Ashif

Reputation: 1684

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

Upvotes: 8

Related Questions