Howto Install and Configure QtCreator on Ubuntu
Install Qt from Ubuntu Software Center,just search qt and select qtcreator, select add-ons
after selecting add-ons, apply thechanges and then install v2.4.1.
Touse Qt in your CMake project, For more info please refer to:http://qt-project.org/quarterly/view/using_cmake_to_build_qt_projects.
Herewe give a complete CMake project using Qt, the complete program canbe download at: http://download.csdn.net/detail/owldestiny/5262651
QtCMakeTest
│ ├── bin
│ ├── build
│ ├── CMakeLists.txt
│ ├── include
│ │ ├── QtCMakeTest.h
│ │ └── QtVtkTest.h~
│ ├── qrc
│ ├── src
│ │ ├── main.cpp
│ │ └── QtCMakeTest.cpp
│ └── ui
│ └── QtCMakeTest.ui
Inthis project we do not use qrc.
TheCMakeLists.txt is:
======================================================================
cmake_minimum_required(VERSION2.8)
project(QtCMakeTest)
#set(CMAKE_BUILD_TYPEdebug)
########################################################
#Qt
find_package(Qt4REQUIRED)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
########################################################
########################################################
#Projectsettings
#set(PROJECT_SOURCESmain.cpp)#all sources files
set(LIBRARY_OUTPUT_PATH${PROJECT_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH${PROJECT_SOURCE_DIR}/bin)
include_directories(${PROJECT_SOURCE_DIR}/include${CMAKE_CURRENT_BINARY_DIR})#to include the moc ui generated ui_*.hs
aux_source_directory(${PROJECT_SOURCE_DIR}/src/PROJECT_SOURCES)
########################################################
########################################################
#GenerateQt files
set(PROJECT_HEADERS${PROJECT_SOURCE_DIR}/include/QtCMakeTest.h)#only headers includeQ_OBJECT
QT4_WRAP_CPP(PROJECT_HEADERS_MOC${PROJECT_HEADERS})
set(PROJECT_UI${PROJECT_SOURCE_DIR}/ui/QtCMakeTest.ui)#ui file
QT4_WRAP_UI(PROJECT_UI_UIC${PROJECT_UI})
#set(PROJECT_RC${PROJECT_SOURCE_DIR}/qrc)#resource files
#QT4_WRAP_RESOURCES(PROJECT_RC_RCC${PROJECT_RC})
########################################################
########################################################
#generateexecutables and link libraries
add_executable(QtCMakeTest${PROJECT_SOURCES} ${PROJECT_HEADERS_MOC} ${PROJECT_UI_UIC})#${PROJECT_RC_RCC})
target_link_libraries(QtCMakeTest${QT_LIBRARIES})
======================================================================
The QtCMakeTest.ui(only including one push button) can be generated and edited by QtDesigner as:
======================================================================
mainWindow
0
0
722
512
Qt CMake Test
430
80
98
51
PushButton
======================================================================
The main.cpp is:
======================================================================
#include
#include "QtCMakeTest.h"
int main(int argc, char**argv)
{
QApplication app(argc,argv);
Qt_QtCMakeTest qtTest;
qtTest.show();
return app.exec();
}
======================================================================
TheQtVtkTest.h is:
======================================================================
#include
#include "ui_QtCMakeTest.h"
class Qt_QtCMakeTest: publicQMainWindow
{
Q_OBJECT
public:
Qt_QtCMakeTest();
public:
Ui::mainWindow ui;
public slots:
void OnButtonClicked();
};
======================================================================
The QtCMakeTest.cpp is:
======================================================================
#include "QtCMakeTest.h"
Qt_QtCMakeTest::Qt_QtCMakeTest()
{
ui.setupUi(this);
connect(this->ui.pushButtonTest, SIGNAL(clicked()), this,SLOT(OnButtonClicked()));
}
voidQt_QtCMakeTest::OnButtonClicked()
{
this->ui.statusbar->showMessage("button clicked");
}
======================================================================