PDA

View Full Version : popupmenu



mickey
28th April 2006, 17:56
Hi , I'm try to insert an item in popupmenu, but problems with connnect to a SLOT


//MyWidget constructor
connect(this, SIGNAL(myUpdate()), myw, SLOT(myUpdateWidgets()) ); //this don't get error
myPopupmenu->insertItem("Zoom out",myw,SLOT(resetMoves() ),3);



QObject::connect: No such slot MainForm::resetMoves()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'MainForm')

Why the first connect works and second get this message from console?

zlatko
28th April 2006, 18:19
have you declare it?

mickey
29th April 2006, 02:27
resetMoves() is a SLOT of myMainForm; I put myw to says this; but connect SEARCH it in MainForm....in mainForm there isn't! It's in myMainForm....

mickey
29th April 2006, 17:52
Hi, now I've tried this:


//constructor of myidget:
myPopupmenu->insertItem("WireFrame", this, SLOT(setWireframe(true)), 4);

The Errors are these:


QObject::connect: No such slot MyWidget::setWireframe(true)
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'myWidget1')
I don't understand: setWireframe(bool) there is and it's a slot; sender name unamed!?
Any hints?

jacek
29th April 2006, 18:37
I don't understand: setWireframe(bool) there is and it's a slot;
Yes, but you try to connect to "setWireframe(true)". You should already know that parameter names and values are forbidden inside SLOT and SIGNAL macros.

mickey
29th April 2006, 19:00
Is 'true' the problem? I change so and get still errors;
I'd like, when I selected item that setWirframe is called with parameter 'true'......


myPopupmenu->insertItem("WireFrame", this, SLOT(setWireframe(bool)), 4);



QObject::connect: Incompatible sender/receiver arguments
QSignal::signal(const QVariant&) --> MyWidget::setWireframe(bool)


In any way I don't understand this error...

jacek
29th April 2006, 19:08
QObject::connect: Incompatible sender/receiver arguments
QSignal::signal(const QVariant&) --> MyWidget::setWireframe(bool)
You can't connect a signal with QVariant parameter to a slot with bool parameter. Both types must be the same.

mickey
29th April 2006, 20:55
Hi! then I tried so and is ok;


myPopupmenu->insertItem("WireFrame", this, SLOT(wire()), 4);
void MyWidget::wire() {
printf("hi\n");
this->setWireframe(true);

}

Otherwise I thinked to insert a SLOT in myPopupmenu that should calls myWidget1->wireFrame(true). but how call setWireframe from a SLOT of myPopupmenu? (myWidget1 is member of myMainForm class) Thanks.

jacek
29th April 2006, 21:49
Otherwise I thinked to insert a SLOT in myPopupmenu that should calls myWidget1->wireFrame(true). but how call setWireframe from a SLOT of myPopupmenu? (myWidget1 is member of myMainForm class)
You would have to subclass QPopupMenu, but your current solution is OK.

mickey
29th April 2006, 23:38
sorry I am still here....I've already subclassed QpopupMenu; my question was (a C++ question): how to call MyWidget instance (myWidget1) from a MyPopupmenu SLOT?
(myMainForm has myWidget1 instance)


void MyPopupmenu::wireframe() {
printf("hi\n");
myWidget1->setWireframe(true); // how to call?
}

jacek
29th April 2006, 23:49
how to call MyWidget instance (myWidget1) from a MyPopupmenu SLOT?
You must give a pointer to that widget to the MyPopupmenu instance. For example as one of the parameters of a constructor.

Since MyWidget is probably the parent of that menu you could use it:
// .h file
class MyWidget;
class MyPopupmenu : public QPopupMenu
{
Q_OBJECT
public:
MyPopupmenu( MyWidget *parent );

private slots:
void wireframe();

private:
MyWidget *_myWidget;
};

// .cpp file:
#include "MyWidget.h"

MyPopupmenu( MyWidget *parent ) : QPopupMenu( parent ), _myWidget( parent )
{
// ...
}

void wireframe()
{
if( _myWidget != 0 ) {
_myWidget->setWireFrame( true );
}
}

mickey
30th April 2006, 18:25
sorry,
but if can't call any SLOT with a parameter, I need to code many slot as the item in qpopmenu....I'm trying this....


myPopupmenu->insertItem(QPixmap::fromMimeSource("wireFrame.png"),
"WireFrame", this, SLOT(CALLpopupmenu()), 0, 0, 1);
myPopupmenu->insertItem(QPixmap::fromMimeSource("zoom_in.png"),
"Zoom in", this, SLOT(CALLpopupmenu()), 0, 1, 2);

void MyWidget::CALLpopupmenu() {
QPopupMenu* item = (QPopupMenu*)sender();
cout << " item " << item << endl; //item hasn't the true value

}

Is thre a way to do this? (in this way or others) thanks in advance

jacek
30th April 2006, 18:49
but if can't call any SLOT with a parameter,
You can invoke a slot with parameter, but its type must match the type of a corresponding signal parameter and you can't specify its value inside the SLOT macro.


I need to code many slot as the item in qpopmenu....
What's wrong with that? What do you want to do in those slots? What signals will be connected to them?

mickey
30th April 2006, 19:09
You can invoke a slot with parameter, but its type must match the type of a corresponding signal parameter and you can't specify its value inside the SLOT macro.
I'd like that wireFrame SLOT starts when I choose an item from myPopupmenu; inserteItem members can only set the receiver...where can I set sender?? Is eg. the item 2, a possilble sender?


What's wrong with that? What do you want to do in those slots? What signals will be connected to them?
Nothing wrong; but so I have some SLOT that calls SLOT; I think is good find a why to use only a SLOT called from item in myPopupmenu (every item has an index or an id); and inside it calls the slots... but I don't know how..

jacek
30th April 2006, 20:22
I'd like that wireFrame SLOT starts when I choose an item from myPopupmenu; inserteItem members can only set the receiver...where can I set sender?? Is eg. the item 2, a possilble sender?
As usual, the answer is in the docs:
void QPopupMenu::activated ( int id ) [signal]
This signal is emitted when a menu item is selected; id is the id of the selected item.
Normally, you connect each menu item to a single slot using QMenuData::insertItem(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is useful in such cases.
See also highlighted() and QMenuData::insertItem().
Examples: grapher/grapher.cpp, helpviewer/helpwindow.cpp, qdir/qdir.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp.
Just connect to this signal instead of supplying slot names to insertItem() method.