Question

I am creating a QSystemTrayIcon traymenu. Its contextmenu has several actions which I need to identify.

public slots:
    void s_showNote();

void Traymenu::createMainContextMenu(){
  ...
  std::string noteTitle = m_noteList[i]->getTitle();

  QString menuEntryName = QString::fromStdString(noteTitle);
  QAction *openNote = m_mainContextMenu.addAction(menuEntryName);

  QObject::connect(openNote,SIGNAL(triggered() ),this,SLOT(s_showNote()) );
      QVariant noteID;
      noteID.setValue(m_noteList[i]->getID());
      openNote->setData(noteID);

The error is

QObject::connect: No such slot QSystemTrayIcon::s_showNote()

All of the code above is a part of my class definition that inherits from QSystemTrayIcon. How can I call the SLOT?

Était-ce utile?

La solution

You seem to have at least two issues ongoing:

  • Use Q_OBJECT for QObject derived classes.

  • You will need to re-run qmake correspondingly.

As for the first point, please use C++11 and at least Qt 5.2 in the future because in cases like this, you will get a static compiler time error which comes handy for avoiding these tedious issues.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top