Reputation: 48916
If I want to make a connection in Qt
as follows:
QObject::connect(quitButton, SIGNAL(clicked()), &myapp, SLOT(quit());
What does &myapp
refer to here? Why should it be used?
Thanks.
Upvotes: 0
Views: 199
Reputation: 264331
What does &myapp refer to here? Why should it be used?
This is the object that will handle the signal (The & takes the objects address (ie. the underlying code uses pointers).
QObject::connect(quitButton, SIGNAL(clicked()), &myapp, SLOT(quit());
When the signal clicked
is activated on the object quitButton
Call the slot quit
on the object myapp
.
A signal is just a method that is called by the object when certain internal state changes. In this case the object will call signal when the user interfaced element is clicked on by the mouse.
The signal method will then call all (slot) methods that have been registered. So in this case when you click on the button signal() is called this in turn will call the quit() method on the object 'myapp`.
Given the way QT examples are normally done. myapp is an application object and the quit() method will cause the main thread to exit from the call to exec().
Upvotes: 1
Reputation: 4022
In this case what you get is that whenever the quitButton
sends the signal clicked it will be sent to the slot quit in myapp
. If the names mean what I think this is probably a button to, well..., quit your app.
Notice there are different versions of connect. It's hard to get the context from a single line of code, but anyway you might wanna check qApp which already represents your application.
EDIT: From another post from you I noticed you asked a trivial question about pointers. So if this is more about what the &
character means, it takes the address of your object. This is pure C++ (nothing specific to Qt).
Upvotes: 2