Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAction's menu() returns NULL
Forum Updated to NodeBB v4.3 + New Features

QAction's menu() returns NULL

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raghaw
    wrote on last edited by
    #1

    Iam trying to retrieve the name of QAction's menu to which its belongs.

    i am dynamically creating QActions and adding to QMenu

    @void MainWindow::addSubProfiles(QString aProfileType, QString aDirectoryName, QString aDirectoryPath)
    {
    QMenu *loMainMenu = new QMenu();
    m_titleBar->m_UserProfileMenu->addMenu(loMainMenu);
    loMainMenu->addSeparator();

    loMainMenu->setTitle(QString(aProfileType) + QString(" (") + aDirectoryName + QString(")"));
    loMainMenu->addSeparator();
    
    QStringList loDirFileNames;
    QDirIterator loFileNamesIter(aDirectoryPath, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags);
    while(loFileNamesIter.hasNext())
    {
        loFileNamesIter.next();
        loDirFileNames << loFileNamesIter.fileName().remove(".ini");
        QString loStrNames = loFileNamesIter.fileName().remove(".ini");
    
        QAction *loProfileActions = new QAction(loStrNames, loMainMenu);
        loProfileActions->setFont(EyGlobalUtilities::getUtilInstance()->getFont());
        loProfileActions->setCheckable(true);
    
        theProfilesActGrp->addAction(loProfileActions);//theProfilesActGrp->QActionAgroup
        loMainMenu->addAction(loProfileActions);
        connect(loProfileActions, SIGNAL(triggered()), this, SLOT(onProfileClicked()));
    }
    
    
    m_titleBar->m_UserProfileMenu->addSeparator();
    

    }

    void EyGuiMainWindow::onProfileClicked()
    {
    QAction loSenderAction = qobject_cast<QAction>(sender());

    qDebug()<<"Currently Active avtion NAme"<<loSenderAction->text();
    qDebug()<<"Currently Active action ActionGroup"<<loSenderAction->menu();
    if(loSenderAction->menu() == NULL)
    {
        qDebug()<<"Menu is NULL";
    }
    setDeleteProfileOption(true);
    

    }@

    here Menu is NULL i recieved .Can anybody let me know what iam doing wrong?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      Hey,

      You are thinking in the wrong direction!

      a QAction can contain a QMenu (as a child item)

      and if set, menu() returns this child menu item... (not the parent)

      To iterate in the other direction you should call parent() (QObject method)

      @
      qDebug()<<"Currently Active action ActionGroup"<<loSenderAction->parent()->metaObject()->className();
      @
      // outputs >> Currently Active action ActionGroup QMenu

      Steven CEUPPENS
      Developer &#x2F; Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved