= qt = Qt is a cross-platform application and UI framework for developers http://qt-project.org/ == Sample C++ Qt program in Slackware Linux == {{{#!highlight c++ /* Include path in Slackware 14: /usr/lib/qt/include/Qt Compile on Slackware 14: g++ -lQtCore -lQtGui -I/usr/lib/qt/include/Qt helloWorldQt.cpp -o helloWorldQt Run with ./helloWorldQt */ #include #include #include int main(int argc,char** argv){ QApplication app(argc,argv); QMainWindow mw; mw.setMinimumSize(200,100); mw.setMaximumSize(200,100); QPushButton pb("Push it, Hello world",&mw); pb.setGeometry(20,20,160,60); mw.setCentralWidget(&pb); mw.show(); return app.exec(); } }}} == Sample CMake + Qt == Adapted from http://cor-net.org/wp-content/uploads/2009/10/HelloWorldQt.tar Structure: * CMakeLists.txt * src\HelloWidget.cpp * src\HelloWidget.h * src\MainWindow.cpp * src\MainWindow.h * src\main.cpp File CMakeLists.txt {{{#!highlight cmake CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(HelloWorldQt) SET(CMAKE_BUILD_TYPE Release) SET(CMAKE_CXX_FLAGS "-Wall") # QT4 Handling FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) SET( HWQ_Qt4_SRC src/MainWindow.h src/HelloWidget.h ) SET( HWQ_Qt4_UI ) SET( HWQ_Qt4_RES ) QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC}) QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI}) QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES}) INCLUDE_DIRECTORIES( . ) # General SET( HWQ_SRC src/main.cpp src/MainWindow.cpp src/HelloWidget.cpp ${HWQ_MOC_CPP} ${HWQ_UI_CPP} ${HWQ_RES_H} ) SET( HWQ_LIB ${QT_LIBRARIES} ) ADD_EXECUTABLE(HelloWorldQt ${HWQ_SRC} ) TARGET_LINK_LIBRARIES(HelloWorldQt ${HWQ_LIB} ) INSTALL_TARGETS( /bin HelloWorldQt) }}} File HelloWidget.cpp {{{#!highlight cpp #include "HelloWidget.h" HelloWidget::HelloWidget(QWidget * parent) : QLabel(parent), _msg("Hello World !"), _pos(0) { } HelloWidget::~HelloWidget() { } void HelloWidget::showNewLetter() { _pos++; setText(_msg.left(_pos)); } }}} File HelloWidget.h {{{#!highlight cpp #include #include #ifndef HELLOWIDGET_H_ #define HELLOWIDGET_H_ class HelloWidget : public QLabel { Q_OBJECT public: HelloWidget(QWidget * parent = 0); ~HelloWidget(); public slots: void showNewLetter(); protected: QString _msg; unsigned short _pos; }; #endif /* HELLOWIDGET_H_ */ }}} File MainWindow.cpp {{{#!highlight cpp #include "MainWindow.h" #include MainWindow::MainWindow(QWidget *parent) { // Making a central Widget for our Window QWidget * centralWidget = new QWidget(this); setCentralWidget(centralWidget); // Building our widgets _helloWidget = new HelloWidget(this); _button = new QPushButton(this); _button->setText("++"); connect(_button, SIGNAL(clicked()), _helloWidget, SLOT(showNewLetter())); // Setting the content and disposition of our central Widget QVBoxLayout * layout = new QVBoxLayout(); layout->addWidget(_helloWidget); layout->addWidget(_button); centralWidget->setLayout(layout); } MainWindow::~MainWindow() { } }}} File MainWindow.h {{{#!highlight cpp #include #include #include "HelloWidget.h" #ifndef MAINWINDOW_H_ #define MAINWINDOW_H_ class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); protected: HelloWidget * _helloWidget; QPushButton * _button; }; #endif /* MAINWINDOW_H_ */ }}} File main.cpp {{{#!highlight cpp #include #include "MainWindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } }}} === Build === * find . -name "*.cmake" | xargs -i rm {} * cmake . * make clean * make * make install