Results 1 to 9 of 9

Thread: Dispatch menu action

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dispatch menu action

    It sounds like you have set up your actions incorrectly, so instead of it behaving the way you want it to, it's behaving the way you've told it to.

    You might find QSignalMapper useful for this problem.

  2. #2
    Join Date
    Mar 2013
    Posts
    34
    Thanks
    1

    Default Re: Dispatch menu action

    It sounds like you have set up your actions incorrectly, so instead of it behaving the way you want it to, it's behaving the way you've told it to.
    Could you please tell what I am doing wrong with this setup:

    mainwindow.h:

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. QLineEdit *title;
    9. QLineEdit *name;
    10. QLineEdit *surname;
    11. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QVBoxLayout *vbox = new QVBoxLayout();
    5. title = new QLineEdit();
    6. vbox->addWidget(title);
    7. name = new QLineEdit();
    8. vbox->addWidget(name);
    9. surname = new QLineEdit();
    10. vbox->addWidget(surname);
    11. QWidget *w = new QWidget(this);
    12. w->setLayout(vbox);
    13. this->setCentralWidget(w);
    14.  
    15. QMenu *undoMenu = menuBar()->addMenu("Edit");
    16. // undoMenu->addAction("Undo", this, SLOT(undo()), QKeySequence::Undo); // does nothing
    17. undoMenu->addAction("Undo", title, SLOT(undo()), QKeySequence::Undo); // undoes only title
    18. }
    To copy to clipboard, switch view to plain text mode 

    And thanks for the QSignalMapper link, I will have a look at it...

Similar Threads

  1. Can't check the action when it has a menu?
    By koilin in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2012, 03:53
  2. Replies: 1
    Last Post: 4th November 2011, 11:25
  3. Action-Menu-Button
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 1st October 2007, 16:41
  4. ToolBar Action With Menu
    By indifference in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2007, 19:37
  5. Action on menu to display ui
    By jochen_r in forum Newbie
    Replies: 10
    Last Post: 10th January 2006, 10:10

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
  •  
Qt is a trademark of The Qt Company.