From e5c7d48ecaba4b0e172693f09072a139047dc951 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 25 Mar 2015 19:46:10 -0400 Subject: [PATCH] change label text on button press --- src/MyWindow.cc | 12 +++++++----- src/MyWindow.h | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MyWindow.cc b/src/MyWindow.cc index 289e890..886ef1b 100644 --- a/src/MyWindow.cc +++ b/src/MyWindow.cc @@ -8,17 +8,19 @@ MyWindow::MyWindow(QWidget * parent) { QHBoxLayout * layout = new QHBoxLayout(); - QPushButton * button = new QPushButton("Press me"); - layout->addWidget(button); + m_button = new QPushButton("Press me"); + layout->addWidget(m_button); - QLabel * label = new QLabel("Label"); - layout->addWidget(label); + m_label = new QLabel("Label"); + layout->addWidget(m_label); setLayout(layout); setWindowTitle("My Qt Application!"); + + connect(m_button, SIGNAL(clicked()), this, SLOT(handleButton())); } void MyWindow::handleButton() { - cerr << "got a button press" << endl; + m_label->setText("The button was pressed"); } diff --git a/src/MyWindow.h b/src/MyWindow.h index 213cf8c..1fdfe3f 100644 --- a/src/MyWindow.h +++ b/src/MyWindow.h @@ -14,6 +14,10 @@ public: private slots: void handleButton(); + +private: + QPushButton * m_button; + QLabel * m_label; }; #endif