Results 1 to 4 of 4

Thread: Enabling/Disabling QActions in QMenus

  1. #1
    Join Date
    Feb 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Enabling/Disabling QActions in QMenus

    I'm converting Qt3 code to Qt4 on Linux, and am having a weird problem. I create QActions and add them to a menu using:

    RemoveAllAction = new QAction(this);
    RemoveAllAction->setText(tr("Re&set All"));
    RemoveAllAction->setToolTip(tr("Reset everything"));
    RemoveAllAction->setShortcut(QKeySequence(tr( "Alt+S" )));
    connect( RemoveAllAction, SIGNAL(triggered()), this, SLOT(RemoveAllAction_activated()));
    ...
    optionsMenu = new QMenu(this);
    clearMenu = new QMenu(this);
    clearMenu->addAction(RemoveAllAction);
    RemoveAllAction->setEnabled(false);
    clearMenu->setTitle("Clear");
    optionsMenu->addMenu(clearMenu);
    ...
    menuBar()->addMenu(optionsMenu);

    When I try to enable the RemoveAllAction QAction later using RemoveAllAction->setEnabled(true), I get a segmentation fault! If I comment out the line that does the disable, the code runs OK. I have several other actions that act the same way I initially thought it might have something to do with the fact that the QAction is in a sub-menu, but since it works OK when I comment out the initial disable (or change the second setEnabled to false). I don't think so. I've spent many hours on this already ! Any ideas?
    Last edited by rshabsin; 15th February 2006 at 21:17.

  2. #2
    Join Date
    Feb 2006
    Location
    Warsaw, Poland
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Enabling/Disabling QActions in QMenus

    Can you put more code? I've made same thing as you (disable action at init, and enable it when i want) w/o seg fault and can't see whats wrong is now

  3. #3
    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: Enabling/Disabling QActions in QMenus

    Maybe you have defined RemoveAllAction variable in more than one place?

  4. #4
    Join Date
    Feb 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Enabling/Disabling QActions in QMenus

    I really don't know what more code I could put in. It's basically all there. There are a few other QActions, etc., but I don't think that would matter. It's really straightforward. I am in the middle of converting to Qt4. I wonder if there's some conflict going on between the Qt4 libraries and the Qt3Support libraries.

    RemoveAllAction is only defined in my .h file, nowhere else.

Similar Threads

  1. Problems with QActions and Pixmaps
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2007, 21:53

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.