can a slot be a global func?
-
can a slot be a global func?
i want to write a timer and its slot...
the slot should be a global func in main.cpp...
how can i write the connect?
thank you -
Slot should be a method inside a class that is derived from QObject. It can be global, I think.
And with the new connection syntax in Qt 5, you can use any method (including a lambda function) as a slot: just pass the functor there.
-
@sierdzio It can be global, I think.
but how connect to a global func? -
Let's see if that works:
void myFunc() { qDebug() << "Aha!"; } int main () { MyClass a; QObject::connect(&a, &MyClass::someSignal, &myFunc); // or just myFunc // ... }