
Originally Posted by
weeezes
I don't know how to create a new signal for an object to emit.
Nothing easier! In your header file, include the following section:
signals:
void yourSignal(); // can also have parameters
...
//rest of class
signals:
void yourSignal(); // can also have parameters
...
//rest of class
To copy to clipboard, switch view to plain text mode
That's it! (Well ok, they can be declared as protected etc., but that can come later). There is no "definition" of signals in the .cpp file, and their return type must be void. Then, in the .cpp file, you will have the following:
retType yourClass::yourFunction(yourParams)
{
...
emit yourSignal();
...
return ...;
}
retType yourClass::yourFunction(yourParams)
{
...
emit yourSignal();
...
return ...;
}
To copy to clipboard, switch view to plain text mode
The emit statement is often located near or at the end of a function. So now an object of type yourClass will emit yourSignal() whenever yourFunction() is called, and that object can be meaningfully connected to a slot.
Hope this helps!
Bookmarks