This forum has been archived. All content is frozen. Please use KDE Discuss instead.

plug/unplugActionList: menu showing duplicate entries

Tags: None
(comma "," separated)
xyfix
Registered Member
Posts
110
Karma
0
I have used the plugActionList in my app before but a new implementation gives me a wrong result
Code: Select all
void Report::initialiseReportMenus()
{
   unplugActionList("m_reportCloseList");
   unplugActionList("m_reportPrintList");

   initialiseReportMenu(m_reportCloseMenu, SLOT (slotReportClose()));

   m_reportClosePlugList.append(m_reportCloseMenu);

   initialiseReportMenu(m_reportPrintMenu, SLOT (slotReportPrint()));

   m_reportPrintPlugList.append(m_reportPrintMenu);

   plugActionList("m_reportCloseList", m_reportClosePlugList );
   plugActionList("m_reportPrintList", m_reportPrintPlugList );
}

void Report::initialiseReportMenus(KActionMenu* menu, const char * slot )
{
   std::vector< REPReport > reports = mainReport->getReports();

   if ( !reports.empty())
   {
     for (size_t i = 0; i < reports.size(); ++i)
     {
      QAction* action = new QAction(this);
      action->setText(QString::fromStdString(reports[i]->getDisplayName()));
      connect (action, SIGNAL(triggered()), this, slot);

      menu->addAction(action);

     }
    } 
   
    menu->setDisabled(reports.empty());   
}


the very first time the menu are empty and greyed out as designed and createGUI() is run, after adding the first report the gui shows "report1" in the dynamic menu, adding the second menu gives me "report1 report1 report2" underneath each other in the menu. The for loop contains only 2 item in the second time it runs.

Help is enormously appreciated.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
What exactly are you trying to achieve?

This problem occurs because:

either m_reportPrintPlugList and m_reportPrintPlugList aren't cleared.
or m_reportCloseMenu and m_reportPrintMenu aren't emptied.

Are you trying to create submenus containing the plugged actions? Or are you trying to create items which are seamlessly inserted into the menu?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
bcooksley,

I guess a bit of both. I have a menubar item "Report" and under it come two items "close" and "print" which on their turn can have actions "report1, report2, ...." that change to the QTabWidget where this report is shown. Indeed my problem was related to the fact that I didn't destroy the objects the qlist items pointed to and didn't cleared the qlist. So added a cleanup routine and my code looks like this now. I also do a cleanup in the destructor of the Report object. The problem now is that it sometimes crashes when closing a report ( not reproducable..yet ). Anyone can see the problem right away? or do I need to use valgrind again. The close action also uses initialiseSubMenu , since the removal of a report implies a change in submenu items.

This is the gdb output:
Program received signal SIGSEGV, Segmentation fault.
0xb6c3c537 in ?? () from /usr/lib/libQtGui.so.4



Code: Select all
Report::Report()
{
  initialiseSubMenus();
  initialiseReportMenus()
}


void Report::initialiseSubMenus()
{
  m_reportCloseMenu = new KActionMenu(tr("Close"), this);
  m_reportPrintMenu = new KActionMenu(tr("Print"), this);
}

void Report::initialiseReportMenus()
{
  cleanup();

  unplugActionList("m_reportCloseList");
  unplugActionList("m_reportPrintList");

  initialiseSubMenu();
 
  initialiseReportMenu(m_reportCloseMenu, SLOT (slotReportClose()));
  m_reportClosePlugList.append(m_reportCloseMenu);

  initialiseReportMenu(m_reportPrintMenu, SLOT (slotReportPrint()));
  m_reportPrintPlugList.append(m_reportPrintMenu);

  plugActionList("m_reportCloseList", m_reportClosePlugList );
  plugActionList("m_reportPrintList", m_reportPrintPlugList );
 
}

void Report::initialiseReportMenus(KActionMenu* menu, const char * slot )
{
  std::vector< REPReport > reports = mainReport->getReports();

  if ( !reports.empty())
  {
    for (size_t i = 0; i < reports.size(); ++i)
    {
        QAction* action = new QAction(this);
        action->setText(QString::fromStdString(reports[i]->getDisplayName()));
        connect (action, SIGNAL(triggered()), this, slot);

        menu->addAction(action);
  }
   menu->setDisabled(reports.empty());
}

void cleanup()
{
  qDeleteAll(m_reportClosePlugList);
  m_reportClosePlugList.clear();

  qDeleteAll(m_reportPrintPlugList);
  m_reportPrintPlugList.clear();
}
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I believe in this case using pluggable menus isn't needed, except for possibly the first time, unless you create it before createGUI() is called.

Either way, the likely cause for this crash is unplugging it after the items have been destroyed. Try unplugging it first.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
Indeed the first time it's created it's before createGUI() has run. The crash hasn't occured any more, because I'm unplugging first before destroying the qlists.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]