Difference between revisions of "Qt/ButtonWidget"
From ProgrammingExamples
< Qt
Daviddoria (Talk | contribs) (→buttonform.ui) |
Daviddoria (Talk | contribs) m (→CMakeLists.txt) |
||
Line 114: | Line 114: | ||
==CMakeLists.txt== | ==CMakeLists.txt== | ||
− | <source lang=" | + | <source lang="cmake"> |
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
Line 129: | Line 129: | ||
ADD_EXECUTABLE(ButtonWidget main.cpp buttonform.h buttonform.cpp ${MOCSrcs} ${UISrcs}) | ADD_EXECUTABLE(ButtonWidget main.cpp buttonform.h buttonform.cpp ${MOCSrcs} ${UISrcs}) | ||
TARGET_LINK_LIBRARIES(ButtonWidget ${QT_LIBRARIES}) | TARGET_LINK_LIBRARIES(ButtonWidget ${QT_LIBRARIES}) | ||
− | |||
− | |||
</source> | </source> |
Latest revision as of 20:25, 6 November 2010
main.cpp
#include <QApplication> #include "buttonform.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); ButtonForm buttonform; buttonform.show(); return app.exec(); }
buttonform.h
#ifndef BUTTONFORM_H #define BUTTONFORM_H #include "ui_buttonform.h" class ButtonForm : public QWidget { Q_OBJECT public: ButtonForm(QWidget *parent = 0); public slots: void pushButton_SetLabelText(); private: Ui::ButtonForm ui; }; #endif
buttonform.cpp
#include <QtGui> #include "buttonform.h" #include <iostream> ButtonForm::ButtonForm(QWidget *parent) : QWidget(parent) { ui.setupUi(this); connect( this->ui.pushButton, SIGNAL( clicked() ), this, SLOT(pushButton_SetLabelText()) ); } void ButtonForm::pushButton_SetLabelText() { this->ui.label->setText("hello"); }
buttonform.ui
This file was created with QtDesigner.
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>ButtonForm</class> <widget class="QWidget" name="ButtonForm"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>130</x> <y>100</y> <width>91</width> <height>28</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>170</x> <y>220</y> <width>61</width> <height>18</height> </rect> </property> <property name="text"> <string>TextLabel</string> </property> </widget> </widget> <resources/> <connections/> </ui>
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(ButtonWidget) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) QT4_WRAP_UI(UISrcs buttonform.ui) QT4_WRAP_CPP(MOCSrcs buttonform.h) include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(ButtonWidget main.cpp buttonform.h buttonform.cpp ${MOCSrcs} ${UISrcs}) TARGET_LINK_LIBRARIES(ButtonWidget ${QT_LIBRARIES})