Creating a custon slot for a QMenu

231 views Asked by At

I'm new in Qt World)
I created a new Qt Application in MSVC 2008
Using Qt Creator added controls I need and one of them is QMenuBar
As I understend the equivalent of CallBack(C#) is Slot in Qt.
I culdn't find any information how to create a custom Slot for QMenu using Qt Creator.

1

There are 1 answers

0
Anthony On BEST ANSWER
  1. Subclass QMenuBar, and call the new class whatever you want, e.g., FancyMenuBar.
  2. Add the Q_OBJECT macro in your class definition (google for more info) in fancymenubar.h.
  3. Add the line public slots: in your class definition, e.g., somewhere between public: and private:.
  4. Add the slot definition under that line, e.g., void fancySlot();.
  5. Implement the slot definition, e.g.,

(in fancymenubar.cpp)

void FancyMenuBar::fancySlot()
{
    // type code here
}

Now you can use the slot via the QObject::connect() function, or use the slot as if it were a normal public function.