Changing a label in Qt <p>I'm trying to make a simple program consisting of a button and a label. When the button is pressed, it should change the label text to whatever is in a QString variable inside the program. Here's my code so far:</p> <p>This is my widget.h file:</p> <pre><code>class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); private: Ui::WidgetClass *ui; QString test; private slots: void myclicked(); }; </code></pre> <p>And here's the implementation of the Widget class:</p> <pre><code>#include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::WidgetClass) { ui-&gt;setupUi(this); test = "hello world"; connect(ui-&gt;pushButton, SIGNAL(clicked()), ui-&gt;label, SLOT(myclicked())); } Widget::~Widget() { delete ui; } void Widget::myclicked(){ ui-&gt;label-&gt;setText(test); } </code></pre> <p>It runs but when the button is clicked, nothing happens. What am I doing wrong?</p> <p>Edit: after i got it working, the text in the label was larger than the label itself, so the text got clipped. I fixed it by adding <code>ui-&gt;label-&gt;adjustSize()</code> to the definition of myclicked().</p>