Results 1 to 15 of 15

Thread: popupmenu

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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)

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.