Reputation: 4419
The simple code I want to run:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
My CMakeLists.txt:
project(SimpleProject)
# The version number
set (SimpleProject_VERSION_MAJOR 1)
set (SimpleProject_Version_MINOR 0)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
When running in qtcreator it says QMainWindow: No such file or directory I'm using GCC 4.61 (64 bit) and Qt 4.8.4 (occurs with qt5 also). So it seems that this has nothing to do with the changes within Qt as I've read somewhere else. When I try to run a simple Qt sample Application suggested by qtcreator, it works fine. Qt is installed and qtcreator is able to find it. But with CMake it won't. Do I have to add something to my CMakeLists so that qtcreator is able to locate Qt?
Upvotes: 1
Views: 8242
Reputation: 4419
I read the documentation and wrote this and it works:
cmake_minimum_required(VERSION 2.8)
PROJECT(SimpleProject)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
SET(SimpleProject_SOURCES main.cpp MainWindow.cpp)
SET(SimpleProject_FORMS MainWindow.ui)
SET(SimpleProject_HEADERS MainWindow.h)
QT4_WRAP_CPP(SimpleProject_HEADERS_MOC ${SimpleProject_HEADERS})
QT4_WRAP_UI(SimpleProject_FORMS_HEADERS ${SimpleProject_FORMS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(SimpleProject
${SimpleProject_SOURCES}
${SimpleProject_HEADERS_MOC}
${SimpleProject_FORMS_HEADERS}
)
TARGET_LINK_LIBRARIES(SimpleProject ${QT_LIBRARIES})
Upvotes: 1