Why are we using * character when we are creating button but we aren’t adding it to app instance?
#include <QApplication>
#include <QPushButton>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QPushButton *button = new QPushButton("Button Text");
QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
button->show();
return app.exec();
}
When should we use *, &, ., ->?
newreturns a pointer, hence the*is used here to define button as a pointer-to-QPushButton, The&is used to reference (get the address of)app, which is then passed toconnect.is equivalent to:
This is all basic C (except new) and C++ covered in any introductory book.