Howto Install and Configure QtCreator on Ubuntu

来源:互联网 发布:fyzf后缀是什么软件 编辑:程序博客网 时间:2024/05/14 04:33

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:

======================================================================

<?xml version="1.0"encoding="UTF-8"?><ui version="4.0"><class>mainWindow</class><widget class="QMainWindow"name="mainWindow"><property name="geometry"><rect><x>0</x><y>0</y><width>722</width><height>512</height></rect></property><property name="windowTitle"><string>Qt CMake Test</string></property><widget class="QWidget"name="centralwidget"><widget class="QPushButton"name="pushButtonTest"><property name="geometry"><rect><x>430</x><y>80</y><width>98</width><height>51</height></rect></property><property name="text"><string>PushButton</string></property></widget></widget><widget class="QStatusBar"name="statusbar"/></widget><resources/><connections/></ui>


======================================================================


The main.cpp is:

======================================================================

#include <QApplication>#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 <QtGui/QMainWindow>#include "ui_QtCMakeTest.h"class Qt_QtCMakeTest: publicQMainWindow{Q_OBJECTpublic: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");}


======================================================================