Search code examples
c++visual-studiouser-interfacewxwidgets

Why does visual studio not open my wxWidgets gui's window(frame)?


I start a project where I use wxWidgets. There are 2 classes and 2 cpp files. 1st class:

#pragma once
#include <wx/wx.h>

class MainFrame:public wxFrame
{
public:
    MainFrame(const wxString& title);
};

2nd class:

#pragma once
#include <wx/wx.h>

class App:public wxApp
{
public:
    bool onInit();
};

1st cpp file:

#include <wx/wx.h>
#include "MainFrame.h"

using namespace std;

MainFrame::MainFrame(const wxString& title) :wxFrame(nullptr, wxID_ANY, title) {

}

2nd cpp file

#include "App.h"
#include <wx/wx.h>
#include "MainFrame.h"

wxIMPLEMENT_APP(App);

bool App::onInit() {
    MainFrame* mainFrame = new MainFrame("main");
    mainFrame->Show();
    return true;
}

After starting debugging visual studio write about running my project's exe file without any errors or warnings, but doesn't open anything. That's why I have only one question, why?

I reopened tutorial and compared codes. They are identical. I trid to reopen visual studio, but I didn't get any changes


Solution

  • The name of the function needs to be OnInit() with a capital O in the beginning, because that is the name of the virtual function it is supposed to override. Your code samples have a lowercase o in the beginning.

    This is exactly the kind of mistake that would not go unnoticed if the function was declared using the override keyword, i.e.

    bool onInit() override;
    

    This way the compiler would issue an error about onInit() not overriding anything.