Reputation: 159
I'm building an application that requires a Qdialog, and a few buttons.
I am attempting to use the Command behavioural design pattern in my implementation. My project so far has 4 classes. (Please excuse the rough UML)
Command
+execute()
zoomInAndOut : Command
+execute()
MenuItem
-QPushButton
-command
+clicked()
Dialog
So within the dialog class, I create a menuItem (which has a QPushButton and Command member variable), and what I need to happen is that when the menuItems button has been clicked, it calls the menuItems "clicked" method (which in turn calls the commands execute method). I know that the "connect" function must be used, however after many, many attempts, I cannot get it to work correctly.
Within Dialog the code roughly looks like this
zoomInAndOut zoomCommand;
menuItem *zoom = new menuItem(new QPushButton("Zoom", this), QRect(QPoint(300, 0), QSize(100, 50)), &zoomCommand);
connect(zoom->getButton(), SIGNAL(clicked()), SLOT(zoom->clicked()));
As mentioned before the connect method is completely wrong, but you can see what I am attempting to achieve. How can I make this work?
Thank you in advance for any help.
Upvotes: 0
Views: 64
Reputation: 1280
Change code
connect(zoom->getButton(), SIGNAL(clicked()), SLOT(zoom->clicked()));
to
connect(zoom->getButton(), SIGNAL(clicked()), zoom, SLOT(clicked()));
Upvotes: 2
Reputation: 1191
Make sure your menuItem class contains the Q_OBJECT
macro the line after the opening {
. And make sure the clicked()
method is in the slots
section of the class body.
Upvotes: 1