ui header file (ui_name.h) not found

Viewed 11626

I've created form, saved it in project directory. And now i want to add some code. So, I've created header file:

#ifndef SORTDIALOG_H
#define SORTDIALOG_H

#include <QtWidgets/QDialog>
#include <QtWidgets/QWidget>


#include "ui_sortdialog.h"


class SortDialog: public QDialog, public Ui::SortDialog
{
    Q_OBJECT
public:
    SortDialog(QWidget *parent=0);
    void setColumnRange(QChar first, QChar last);
}

#endif // SORTDIALOG_H

during writing code Qt creator see ui_sortdialog.h, and i, for example, can see "Ui" namespace. But when i'n trying to compiler writes that ui_sortdialog.h wasn't found

C:\Qt\Qt5.1.1\Tools\QtCreator\bin\untitled2\sortdialog.h:8: error: ui_sortdialog.h: No such file or directory
 #include "ui_sortdialog.h"
                       ^
4 Answers

For people who come here that don't have a .pro file and don't use qmake, but cmake:

Instead of:

add_executable(myprogram
    gui.cpp
    gui.ui
    main.cpp
)

Use:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

add_executable(myprogram
    gui.cpp
    gui.ui
    main.cpp
)

Or:

qt5_wrap_cpp(UI_SOURCES
    gui.cpp
)
qt5_wrap_ui(UI_HEADERS
    gui.ui
)
add_executable(myprogram
    main.cpp
    ${UI_SOURCES}
    ${UI_HEADERS}
)

FYI: The ui_gui.h header will be generated at ${CMAKE_CURRENT_BINARY_DIR}. Sources:

Related