Ruslan F.
Ruslan F.

Reputation: 5776

Creating a custon slot for a QMenu

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.

Upvotes: -1

Views: 233

Answers (1)

Anthony
Anthony

Reputation: 8788

  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.

Upvotes: 1

Related Questions