[Beginner Question] Cannot get this Code to run
-
Hello Community, i play a little bit with signals/slots (hte manual way) but my code does not work.
@
#include <QtGui>
#include <QMessageBox>class Demo : public QObject
{
Q_OBJECTpublic slots:
void showMessage();public:
Demo(){}
};
void Demo::showMessage()
{
QMessageBox::information(0,"Message","Hello World",QMessageBox::Ok);}
int main(int argc, char* argv[])
{
QApplication app(argc,argv);//Create a new QPushButton QPushButton * button = new QPushButton("Hello Wolrd!"); button->show();
//Construct my Class
Demo *dapp = new Demo();//Here i try to connect that on pressing the Button the Demo->showMessage Member will be displayed
QObject::connect(&button,SIGNAL(clicked()),&app,SLOT(showMessage()));return app.exec();
}
@What did i wrong in the connect Member?
Thanks for Help!
-
The "&button" should really just be "button". button already is a pointer, no need to turn it into a pointer to a pointer...
-
Sorry, but you are a little bit inconsecutive (see the "star" place):
char* argv[]
Demo *dapp
QPushButton * buttonThis can confuse other developers.
Be consecutive!When you declare (or define) a pointer, bind the "star" to the type, and when you dereference a pointer, bind the "star" to the variable name.