Qt/ButtonWidgetMultipleInheritance
From ProgrammingExamples
< Qt
main.cpp
#include <QApplication> #include "buttonform.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyForm form; form.show(); return app.exec(); }
buttonform.h
#ifndef BUTTONFORM_H #define BUTTONFORM_H #include "ui_buttonform.h" class MyForm : public QWidget, private Ui::ButtonForm { Q_OBJECT public: MyForm(QWidget *parent = 0); public slots: void pushButton_SetLabelText(); }; #endif
buttonform.cpp
#include "buttonform.h" MyForm::MyForm(QWidget *parent) : QWidget(parent) { setupUi(this); connect( this->pushButton, SIGNAL( clicked() ), this, SLOT(pushButton_SetLabelText()) ); } void MyForm::pushButton_SetLabelText() { this->label->setText("hello"); }
buttonform.ui
<?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>My Program</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>Click me</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>150</y>
<width>61</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Before click</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(MultipleInheritance) 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(MultipleInheritance main.cpp buttonform.h buttonform.cpp ${MOCSrcs} ${UISrcs}) TARGET_LINK_LIBRARIES(MultipleInheritance ${QT_LIBRARIES})