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"
^
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).
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/
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).
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:
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