Results 1 to 15 of 15

Thread: popupmenu

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default popupmenu

    Hi , I'm try to insert an item in popupmenu, but problems with connnect to a SLOT
    Qt Code:
    1. //MyWidget constructor
    2. connect(this, SIGNAL(myUpdate()), myw, SLOT(myUpdateWidgets()) ); //this don't get error
    3. myPopupmenu->insertItem("Zoom out",myw,SLOT(resetMoves() ),3);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QObject::connect: No such slot MainForm::resetMoves()
    2. QObject::connect: (sender name: 'unnamed')
    3. QObject::connect: (receiver name: 'MainForm')
    To copy to clipboard, switch view to plain text mode 
    Why the first connect works and second get this message from console?
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    have you declare it?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    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....
    Regards

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    Hi, now I've tried this:
    Qt Code:
    1. //constructor of myidget:
    2. myPopupmenu->insertItem("WireFrame", this, SLOT(setWireframe(true)), 4);
    To copy to clipboard, switch view to plain text mode 
    The Errors are these:
    Qt Code:
    1. QObject::connect: No such slot MyWidget::setWireframe(true)
    2. QObject::connect: (sender name: 'unnamed')
    3. QObject::connect: (receiver name: 'myWidget1')
    To copy to clipboard, switch view to plain text mode 
    I don't understand: setWireframe(bool) there is and it's a slot; sender name unamed!?
    Any hints?
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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.

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    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'......
    Qt Code:
    1. myPopupmenu->insertItem("WireFrame", this, SLOT(setWireframe(bool)), 4);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QObject::connect: Incompatible sender/receiver arguments
    2. QSignal::signal(const QVariant&) --> MyWidget::setWireframe(bool)
    To copy to clipboard, switch view to plain text mode 
    In any way I don't understand this error...
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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.

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    Hi! then I tried so and is ok;
    Qt Code:
    1. myPopupmenu->insertItem("WireFrame", this, SLOT(wire()), 4);
    2. void MyWidget::wire() {
    3. printf("hi\n");
    4. this->setWireframe(true);
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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.

  10. #10
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    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)
    Qt Code:
    1. void MyPopupmenu::wireframe() {
    2. printf("hi\n");
    3. myWidget1->setWireframe(true); // how to call?
    4. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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:
    Qt Code:
    1. // .h file
    2. class MyWidget;
    3. class MyPopupmenu : public QPopupMenu
    4. {
    5. Q_OBJECT
    6. public:
    7. MyPopupmenu( MyWidget *parent );
    8.  
    9. private slots:
    10. void wireframe();
    11.  
    12. private:
    13. MyWidget *_myWidget;
    14. };
    15.  
    16. // .cpp file:
    17. #include "MyWidget.h"
    18.  
    19. MyPopupmenu( MyWidget *parent ) : QPopupMenu( parent ), _myWidget( parent )
    20. {
    21. // ...
    22. }
    23.  
    24. void wireframe()
    25. {
    26. if( _myWidget != 0 ) {
    27. _myWidget->setWireFrame( true );
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to jacek for this useful post:

    mickey (30th April 2006)

  13. #12
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    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....
    Qt Code:
    1. myPopupmenu->insertItem(QPixmap::fromMimeSource("wireFrame.png"),
    2. "WireFrame", this, SLOT(CALLpopupmenu()), 0, 0, 1);
    3. myPopupmenu->insertItem(QPixmap::fromMimeSource("zoom_in.png"),
    4. "Zoom in", this, SLOT(CALLpopupmenu()), 0, 1, 2);
    5.  
    6. void MyWidget::CALLpopupmenu() {
    7. QPopupMenu* item = (QPopupMenu*)sender();
    8. cout << " item " << item << endl; //item hasn't the true value
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

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

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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.

    Quote Originally Posted by mickey
    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?

  15. #14
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: popupmenu

    Quote Originally Posted by jacek
    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?
    Quote Originally Posted by jacek
    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..
    Regards

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popupmenu

    Quote Originally Posted by mickey
    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.

Similar Threads

  1. qtablewidget popupmenu
    By totosugito in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2008, 05:51
  2. get Text from Popupmenu action
    By raphaelf in forum Newbie
    Replies: 6
    Last Post: 11th October 2006, 15:24
  3. PopupMenu
    By jnana in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2006, 06:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.