Home » Community » Newbie corner » Focus problem
Re: Focus problem [message #57816 is a reply to message #57812] |
Sun, 19 December 2021 14:22   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Silvan:
The way I define WhenSuspiciousKey is a typical way to define an Event. First, the Ctrl or its direvative need to provide a chance for the event in a (relevant) overrided virtual function. In my case, I overrided
In my MainWindow::Key(...)
I allowed WhenSuspiciousKey be called at certain time. What is WhenSuspiciousKey? I define it as a member variable of MainWindow of type Event<>
By add this member variable to MainWindow, the user of MainWindow can assign a callback to an instance(object) of this type by
MainWindow m;
m<<[]{...};
There is no magic here. C have simlar (but much limited ) mechanism. WhenSuspiciousKey is like a function pointer to which you can assign a callback. In order for this callback to actually be called, some where, you need to check and call it(in our case, it's in the MainWindow::Key(...) virtual function).
Now, Key is a virtual function, you cannot assign a callback to it. On the other hand, an object of MainWindow, m, has a public member variable name WhenSuspciciousKey, which is of type Event<>. You can access this member variable. One way is by something like
m.WhenSuspiciousKey<<[]{};
-----
PS: On a second thought, use C function pointer as example:
void (*WhenWhat)(int);
void func1(int p)
{
if(WhenWhat)
WhenWhat(p);
}
void callback(int p)
{
}
WhenWhat=callback; // this is good
// just like
// WhenSuspiciousKey<<[]{};
// is fine
func1=callback; // this won't compile
// just like
// Key<<[]{};
// won't compile.
[Updated on: Sun, 19 December 2021 15:02] Report message to a moderator
|
|
|
 |
|
Focus problem
By: Silvan on Tue, 14 December 2021 21:23
|
 |
|
Re: Focus problem
By: Silvan on Wed, 15 December 2021 14:28
|
 |
|
Re: Focus problem
By: Silvan on Fri, 17 December 2021 23:01
|
 |
|
Re: Focus problem
By: Lance on Sat, 18 December 2021 05:39
|
 |
|
Re: Focus problem
By: Silvan on Sat, 18 December 2021 16:03
|
 |
|
Re: Focus problem
By: Silvan on Sat, 18 December 2021 16:22
|
 |
|
Re: Focus problem
By: Lance on Sat, 18 December 2021 17:17
|
 |
|
Re: Focus problem
By: Lance on Sat, 18 December 2021 17:24
|
 |
|
Re: Focus problem
By: Silvan on Sat, 18 December 2021 18:32
|
 |
|
Re: Focus problem
By: Silvan on Sun, 19 December 2021 12:23
|
 |
|
Re: Focus problem
By: Lance on Sun, 19 December 2021 14:22
|
 |
|
Re: Focus problem
By: Lance on Sun, 19 December 2021 14:31
|
 |
|
Re: Focus problem
By: Lance on Sun, 19 December 2021 14:44
|
 |
|
Re: Focus problem
By: Silvan on Sun, 19 December 2021 15:37
|
 |
|
Re: Focus problem
By: Silvan on Sun, 19 December 2021 15:59
|
 |
|
Re: Focus problem
By: Lance on Sun, 19 December 2021 16:16
|
 |
|
Re: Focus problem
By: Lance on Sun, 19 December 2021 16:24
|
 |
|
Re: Focus problem
By: Silvan on Sun, 19 December 2021 19:31
|
 |
|
Re: Focus problem
By: Lance on Mon, 20 December 2021 13:43
|
Goto Forum:
Current Time: Sun Aug 24 20:29:02 CEST 2025
Total time taken to generate the page: 0.05301 seconds
|