Well, I've read the signals and slots chapter, but I'm still lost.
I'm sure that reading the entire tutorial will slowly give me a better understanding of Qt. But shouldn't a simple thing be just as simple to learn ?

For example, I have a simple test program with just a push button and I want to make it so that when the button is pressed it's label changes.

Now I've tried to write a slot function in the corresponding .cpp file (just the standard file you get when creating a new C++ GUI application), like this:

void MainWindow:: on_button_clicked()
{
}

The function is properly registered as a slot and I checked that it is actually called.
So, what do I have to put in there for the respective push button that sent the signal to change its label ?

I looked up that the QPushButton class inherits a setText() method for the purpose of setting its label. But I can't seem to be able to get a reference to the button in order to call it's member function. The GUI is automatically designed by Qt Creator and, though I see the QPushButton object in the respective "ui_mainwindow.h" if I specifically open it, I have no idea how to get a reference to it at the point where I defined the slot and want to change its text.

Then I found in the signal and slot chapter that there is the QObject sender() function.
So I queried the current QObject (the main window) for the sender of the signal and tried to change its Text, like this:

this->sender()->setText("Hi");

But the problem seems to be that the returned reference is a generic QObject and not QPushButton, so there is no function "setText" to do that.

I'm sure there must a simple way to do what I try to do. I just don't see it.
Could someone please give me a simple hint on how to do that and why my approach didn't work ?



Also, I have another question about signals and slots:

In the chapter about signals and slots (http://doc.trolltech.com/latest/signalsandslots.html) it says:

"Signals are automatically generated by the moc and must not be implemented in the .cpp file."

But why does it seem then like that is done in the very example above (class Counter) where a signal function is defined ?