
Originally Posted by
roxton
But why the iteration through the parents works in a such strange way?
Hmm, good question. According to my test case it works fine:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
QMenu* subMenu
= menu.
addMenu("Bar");
QAction* action
= subMenu
->addAction
("File");
QMenu *m_parent
= qobject_cast<QMenu
*>
(action
->parentWidget
());
while (m_parent)
{
path.prepend("/").prepend (m_parent->title());
m_parent = qobject_cast<QMenu *> (m_parent->parentWidget());
}
qDebug() << path; // outputs "Foo/Bar/File" for me
}
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMenu menu("Foo");
QMenu* subMenu = menu.addMenu("Bar");
QAction* action = subMenu->addAction("File");
QString path = action->text();
QMenu *m_parent = qobject_cast<QMenu *> (action->parentWidget());
while (m_parent)
{
path.prepend("/").prepend (m_parent->title());
m_parent = qobject_cast<QMenu *> (m_parent->parentWidget());
}
qDebug() << path; // outputs "Foo/Bar/File" for me
}
To copy to clipboard, switch view to plain text mode
Perhaps there's something wrong with the menu hierarchy construction?
Bookmarks