OnButton1Click(event); error: no matching function for call to.. Using Timer Event.

I thought I would update this post

I have a OnButton1Click(event); in use for a wxGrid records display refresh, and it works perfectly when used under multiple other ButtonClick(event).

When I place this OnButton1Click(event); under an OnTimer1Trigger event it produces the compile error:

`error: no matching function for call to wxSQLi_417Frame::OnButton2Click(wxTimerEvent&)’

My code:
1
2
3
4
void wxSQLi_417Frame::OnTimer1Trigger(wxTimerEvent& event)
{
     OnButton2Click(event);
}


What could I add to satisfy this? I have never encountered this before.

Any advice appreciated.
Last edited on
OK, it sounds like you're trying to compile a Windows API based program on a Linux machine.

If this is the case then you're running into the fact that Windows API is not cross-platform. You would run into the same error if you tried to compile for Mac, Unix, Android... any system that is not Windows.

You could try converting the code to Qt, SDL, SFML, or one of dozens of cross-platform libraries out there, but windows.h is a no-fly zone. (Technically you could use "Wine" to run windows-compiled code https://en.wikipedia.org/wiki/Wine_(software) )


Edit: I like the improved prompt, it's well worded and provides some information about the original code.
Last edited on
OK, it sounds like you're trying to compile a Windows API based program on a Linux machine.


No I am not, I'm converting (making all necessary code changes for the new platform).
I know better than to attempt to compile a Windows version...

Was just curious about doing an OnButtonClick(event) programmatically.
Last edited on
You are not providing enough information. What library are you converting to?

All three libraries that I mention above have interfaces to a GUI, mouse and keyboard (All of which could be a reference to a "ButtonClick") and they are event driven. I know SDL2 uses what it calls a pollevent loop which allows for an input que (events are generally given to you one at a time). Qt tend towards throwing signals out to everything and it's the job of each object to either catch and react to it or just ignore it (Signals and slots method).

I don't remember what SFML uses, but I'd guess it's similar to SDL.

I don't remember an
OnButton2Click(event);
function in the Windows API. It kind of sounds like a framework is involved in the code. Can you provide the original demo code that you are looking at?


Prompt well fixed.
Last edited on
The is the original code from my project in a Win 7 PC with C::B 16.01 & wxWidgets 3.02.
Works perfectly.

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
void wxSQLite2Frame::OnButton1Click(wxCommandEvent& event)
{
    wxString testDBName = wxGetCwd() + wxT("/testDb.db");
    db->Open(testDBName);
    db->ExecuteUpdate(wxString::Format(_("%s"),Query->GetValue()));
    db->Close();
    StatusBar1->SetStatusText(_("Query: ")+Query->GetValue());
    Query->SetValue(_(""));
    OnButton2Click(event);
}

void wxSQLite2Frame::OnButton2Click(wxCommandEvent& event)
{
  wxString testDBName = wxGetCwd() + wxT("/testDb.db");
    db->Open(testDBName);
    wxSQLite3ResultSet Res = db->ExecuteQuery(wxString::Format(_("%s"),Select->GetValue()));
    Grid1->ClearGrid();
    int count = 0;

    while (Res.NextRow())
    {
        Grid1->SetCellValue(count,0,wxString::Format(_("%s"),Res.GetAsString(0)) ) ;
        Grid1->SetCellValue(count,1,wxString::Format(_("%i"),Res.GetInt(1)) ) ;
        Grid1->SetCellValue(count,2,wxString::Format(_("%s"),Res.GetAsString(2)) ) ;
      //  Grid1->SetCellValue(count,3,wxString::Format(_("%s"),Res.GetAsString(3)) ) ;
        count++;
    }
I haven't used wxWidgets, but this could be an issue with codeblocks. How did you port this over to the linux machine? Did you just copy the entire project folder, or zip it, or what?

I'm currently thinking that there might be something windows-specific in the *.cbp file or some other issue that is preventing the proper linking of your headers at compile time. Perhaps you have some precompiled objects (*.o files) from previous compile on Windows.

Try creating a new project and add the *.cpp and *.h files into the project manually.

You might also try the Wx official forums, https://forums.wxwidgets.org/index.php
Last edited on
Updated post.

The OnButton#Click(event); only fails to operate under a Timer event now.
Last edited on
I still do not have any experience in wxWidgets, but something does stand out. The event that you are passing from OnTimer1Trigger() is from a wxTimerEvent, but OnButton2Click() is expecting a wxCommandEvent.

Can you overload OnButton2Click to accept the wxTimerEvent type?


Edit: Actually, the calling function in the prompt is a snippet from the "wxSQLi_417Frame" class, so calling OnButton2Click() is not calling wxSQLite2Frame::OnButton2Click().
Do you have a wxSQLite2Frame object inside of your wxSQLi_417Frame class that you could call?

Double Edit:
I remember asking you to post the original code and that's what you provide in the lower code sample. You said you'd made modifications which could explain some of the confusion in my previous edit. Can we see the new code for OnButton2Click()?
Last edited on
Can we see the new code for OnButton2Click()?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//*************** Refresh Button **************************
void wxSQLi_417Frame::OnButton2Click(wxCommandEvent& event)
{
  wxSQLite3Database* db = new wxSQLite3Database();
  wxString testDBName = wxGetCwd() + wxT("/database.db");
    db->Open(testDBName);
   wxSQLite3ResultSet Res = db->ExecuteQuery(wxString::Format(_("%s"),txtSQL->GetValue()));

  Grid1->ClearGrid();
    int count = 0;

    while (Res.NextRow())
    {
        Grid1->SetCellValue(count,0,wxString::Format(_("%s"),Res.GetAsString(0)) ) ;
        Grid1->SetCellValue(count,1,wxString::Format(_("%i"),Res.GetInt(1)) ) ;
        Grid1->SetCellValue(count,2,wxString::Format(_("%s"),Res.GetAsString(2)) ) ;
        Grid1->SetCellValue(count,3,wxString::Format(_("%s"),Res.GetAsString(3)) ) ;
        Grid1->SetCellValue(count,4,wxString::Format(_("%s"),Res.GetAsString(4)) ) ;
        count++;
    }
}
This looks promising. I think you only have to overload OnButton2Click() to take a wxTimerEvent. (Make sure to do that in both the cpp file and the h file.

That or perhaps wxTimerEvent can be cast to a wxCommandEvent. They both inherit from the wxEvent class so it would make sense for casting to work.

Try type-casting first, it would save you time if it works:
1
2
3
4
void wxSQLi_417Frame::OnTimer1Trigger( wxTimerEvent& event)
{
     OnButton2Click((wxCommandEvent) event);
}


If that fails then you would next have to try overloading the function:
1
2
3
4
5
void wxSQLi_417Frame::OnButton2Click(wxTimerEvent& event)
{
    // copy and paste all the code from the original function into here.
    // Luckily the event itself is never used so there are no conflicts inside the function.
}


[Please, anyone with experience in wxWidgets feel free to step in]
Last edited on
[SOLVED]

I created a new method/function named:
void wxSQLi_417Frame::DisUpdate()

Containing the wxGrid data refresh code from my OnButton2Click event above.

Added a declaration in my AppMain.h header file:
void DisUpdate();

Now I can refresh my data display wxGrid from anywhere, including the Timer event, using DisUpdate().

Thanks to everyone for your contributions.
Last edited on
Topic archived. No new replies allowed.