Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui header file (ui_name.h) not found

Tags:

c++

qt

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"
                       ^
like image 406
user3102246 Avatar asked Dec 14 '13 13:12

user3102246


4 Answers

You created a form called sortdialog, right? If you did it using Qt Creator, it was supposed to add the following line to your project's .pro file:

FORMS += sortdialog.ui

If there is no such line, add it to the .pro file.

When a project has .ui files, a command called uic is called as part of the build process. This uic ("ui compiler") is responsible for the generation of ui_sortdialog.h, in you case.

You rarely need to call it directly, running qmake prior to make should do it for you (if the aforementioned FORMS line is in you .pro file).

like image 190
anselmolsm Avatar answered Nov 01 '22 11:11

anselmolsm


Qt sometimes experiences difficulties when the build directory is at the same folder as the *.pro file.

I suggest making sure that your build directory is one level higher in the directory structure than the project file.

The following directory structure is prone to error:

MyProj/proj.pro
MyProj/builds/

The following directory structure will avoid this issue:

MyProj/proj.pro
MyProjBuild/

like image 32
J.Javan Avatar answered Nov 01 '22 12:11

J.Javan


I had this problem. Here is what I had to fix: Make sure that sortdialog.cpp and sortdialog.ui are both in the pro file in the appropriate sections with the appropriate case (upper or lower exactly as in the file names).

like image 24
user1741137 Avatar answered Nov 01 '22 12:11

user1741137


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:

  • unable to include a ui_form header of QT5 in cmake
  • Qt 5 cmake fails with undefined reference to vtable on hello world with inc & src as subdirs
like image 28
stackprotector Avatar answered Nov 01 '22 11:11

stackprotector