Hello! I write the code that shows a part of file system as the menu. Subfolders are the submenus, etc. All works fine, but now I need to write a slot for the "filename" menu item selection.
In that slot, I need to determine a sequence of parent titles to make a path for the file.
For example, my menu structure is: Foo - Bar - file.txt
When I click on the file.txt menu item, I need to iterate through the parents to get their titles.
So my code is:
This code have a strange behavior - the nearest (previous) upper level "directory" is dropped out. So I have not Foo/Bar/file.txt, but Foo/file.txt instead.Qt Code:
void rvln::test_slot() { QString path; path.prepend (a->text()); while (m_parent) { path.prepend("/").prepend (m_parent->title()); m_parent = qobject_cast<QMenu *> (m_parent->parentWidget()); } qDebug() << path; }To copy to clipboard, switch view to plain text mode
Bookmarks