Hello,
I’m developping a project using Qt5, and compiling it with CMake. Here’s my CMakeLists:
# Uses 2.8.8 features
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
# Configuring project
PROJECT(myProject)
# Tell CMake to run moc when necessary
SET(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
# To switch between g++ and clang++
SET(CMAKE_CXX_COMPILER "/usr/bin/clang++")
# Commong flags
SET(CMAKE_CXX_FLAGS "-Wall -std=c++11")
# Defining to flags regarding to configurations
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
# Widgets finds its own dependencies.
FIND_PACKAGE(Qt5Widgets REQUIRED)
# Selecting files to compile
FILE(
GLOB_RECURSE
SOURCE_FILES
src/*.cpp
)
FILE(
GLOB_RECURSE
UI_FILES
src/*.ui
)
QT5_WRAP_UI(UI_HEADERS ${UI_FILES})
# Binary declaration
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCE_FILES} ${UI_HEADERS} ${UI_FILES})
QT5_USE_MODULES(${PROJECT_NAME} Widgets)
And here is the class where the issues is located:
#ifndef NEWCLASSGENERATORDIALOG_HPP
#define NEWCLASSGENERATORDIALOG_HPP
#include <QtCore/QDate>
#include <QCompleter>
#include <QtWidgets/QDialog>
namespace Ui
{
class NewClassGeneratorDialog;
}
class NewClassGeneratorDialog : public QDialog
{
Q_OBJECT
public:
explicit NewClassGeneratorDialog(QWidget* parent = nullptr);
~NewClassGeneratorDialog();
private slots:
private:
Ui::NewClassGeneratorDialog* _ui;
};
#endif // NEWCLASSGENERATORDIALOG_HPP
The its implementation:
#include "newClassGeneratorDialog.hpp"
#include "ui_newClassGeneratorDialog.h"
NewClassGeneratorDialog::NewClassGeneratorDialog(QWidget* parent) : QDialog(parent), _ui(new Ui::NewClassGeneratorDialog)
{
_ui->setupUi(this);
}
NewClassGeneratorDialog::~NewClassGeneratorDialog()
{
delete _ui;
}
And the errors I get:
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.cpp:30:94: error: allocation of incomplete type ‘Ui::NewClassGeneratorDialog’
NewClassGeneratorDialog::NewClassGeneratorDialog(QWidget* parent) : QDialog(parent), _ui(new Ui::NewClassGeneratorDialog)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.hpp:36:11: note: forward declaration of ‘Ui::NewClassGeneratorDialog’
class NewClassGeneratorDialog;
^
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.cpp:32:8: error: member access into incomplete type ‘Ui::NewClassGeneratorDialog’
_ui->setupUi(this);
^
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.hpp:36:11: note: forward declaration of ‘Ui::NewClassGeneratorDialog’
class NewClassGeneratorDialog;
^
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.cpp:37:5: warning: deleting pointer to incomplete type ‘Ui::NewClassGeneratorDialog’ may cause undefined behaviour [-Wdelete-incomplete]
delete _ui;
^ ~~~
/home/kevina/Documents/myProject/src/newClassGeneratorDialog.hpp:36:11: note: forward declaration of ‘Ui::NewClassGeneratorDialog’
class NewClassGeneratorDialog;
Thanks in advance ;)
↧