View Single Post
Nathraiben's Avatar
Posts: 267 | Thanked: 408 times | Joined on May 2010 @ Austria
#7
Originally Posted by D-Iivil View Post
Heh, well, got it running on the device.

Now the hardest part: how to make the buttons actually to do something :-P
Okay, first the obligatory warning: I'm pretty new to Qt, so I might be spouting a lot of nonsense, but here's how I got it to work:

In the constructor of your window widget, connect the "clicked" event of your button:

Code:
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(hello()));
Note:
"ui" is the... well, UI defined by "ui(new Ui::MyWindowName)" in the constructor
"pushButton" is the name of your button
"hello()" is the name of a slot created in the next step


In the header file of the window widget, add the definition for a new slot (inside the class definition) :

Code:
protected slots:
        void hello();

Back in the implementation file of your window widget, define a function for that slot:

Code:
void MainWindow::hello()
{
    //Do whatever should be done when pressing the button
}

Just don't call the spot hello - that was obviously taken from my inevitable first Hello World app.
 

The Following 2 Users Say Thank You to Nathraiben For This Useful Post: