change label text on button press

This commit is contained in:
Josh Holtrop 2015-03-25 19:46:10 -04:00
parent 64e3d89818
commit e5c7d48eca
2 changed files with 11 additions and 5 deletions

View File

@ -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");
}

View File

@ -14,6 +14,10 @@ public:
private slots:
void handleButton();
private:
QPushButton * m_button;
QLabel * m_label;
};
#endif