C++ Call non static function on another function

Pages: 12
I have the following code

1
2
3
4
5
6
7
8
9
10
void APPDlg::set()
{
    WxGauge1->SetValue(20);
{

void Thread(void *)
{
    system("start run.exe");
    //how to call "APPDlg::set" non static function here?
}


how to call "APPDlg::set" non static function after system in void threat?

Thanks!!!
Last edited on
ok...what is the question?

how to call "APPDlg::set" non static function after system in void threat?
It's a class function. Make an object of that class, and then call it on that object.

Alternatively, make it a static function of the class (with the static keyword), but be aware that you will then only be able to access static member variables with it.
Michelins wrote:
how to call "APPDlg::set" non static function after system in void threat?
Pass 'new APPDlg' when you create the thread. And within the thread
1
2
3
4
5
6
7
8
9
void Thread(void *p)
{
  APPDlg *a = (APPDlg *) p;

  a->set();

    system("start run.exe");
    //how to call "APPDlg::set" non static function here?
}
But be warned: it's very problematic to call any gui function from another thread
coder777

much obliged

indeed, the proposed solution worked, the more the program crash when you reach the point of calling a GUI object ...

what can I do to set this object WxGauge within the thread?
:(
:((
Michelins wrote:
what can I do to set this object WxGauge within the thread?
Don't do it directly. Store the value in a member variable and then read this variable from a timer event of that window and set it to the WxGauge.

Note that I observed that the timer event may interfere with other events. So use 'wxCriticalSection' especially before you disconnect the timer event.
good, thanks for the help;

seen here, who declare themselves as well

1
2
3
4
void APPDlg::set(wxCommandEvent& event)
{
    WxGauge1->SetValue(20);
{


works, more to do so

1
2
        APPDlg *a = (APPDlg *) p;
        a->set(wxCommandEvent& event);


gives this error

1
2
3
no matching function for call to `APPDlg::set()'

candidates are: void APPDlg::set(wxActivateEvent&) 


Any idea what it is?

Thanks!!!
Last edited on
...
Please :(
hm, I don't see what's the idea behind setting the value always to 20?

What I thought of was something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class APPDlg
{
  int Value;

public:
  APPDlg()
  {
    // Start timer
  }
  ~APPDlg()
  {
    // End timer
  }

  void TimerEvent(wxTimerEvent &e)
  {
    WxGauge1->SetValue(Value);
  }

  void SetValue(int v)
  {
    Value = v;
  }
};

...

void Thread(void *p)
{
  APPDlg *a = (APPDlg *) p;

  a->SetValue(20);

    system("start run.exe");
}
Well, there are several Threats, and each is assigned a different value

Thanks for the tip, plus the program crashed (APPCRASH) again :(
please :(
if you 'a->SetValue(20);' and it still crashes then 'p' can't be the pointer to 'APPDlg'. Or there's something else that causes the crash.
Well, I noticed that if I put something from the GUI, the program gives APP CRASH, over whether to put another statement, it works normally ...
please :((
So do you understand what I mean with 'time event'?
Well, I do not know what it is, the more I put the code in the same way that you quoted above,and did not

wxTimer tried with and gave the same, APP Crash

Thanks
Pages: 12