Solved How do I write a slot method in main, I want to write this slot method outside of main
-
How do I write a slot method in main, and I want to write this slot method outside of main, but I can't seem to find the proper syntax
int main(int argc, char *argv[]) { } void slotToDo(){ }
-
It's just a regular function. There's no special syntax to it.
If you want to use it inside main it has to be declared above it, like with any other function.How are you using it and what error do you get exactly?
-
@Chris-Kawa
I mean it can't be bound with the connect method like a class, how can the connect syntax be written -
Just like for a class member. For example to connect it to a button click:
QObject::connect(button, &QPushButton::clicked, &slotToDo);
-
@Chris-Kawa
Can I define a signal above main and emit it? -
No, signals are different. They are QObject derived class members and are generated with moc (the meta-object compiler). A signal is kinda what its name implies - it signals a change in some object and making a connection to it subscribes you to notifications about changes in that object. If there's no object there's nothing to signal a change in.
It's kinda like subscribing to notifications from some website - if there's no website who would you get notifications from?