error: allocating an object of abstract class type 'wxImageHandler' [wxSmith, wxWidgets 3.1.3] [Solved]

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

error: allocating an object of abstract class type 'wxImageHandler' [wxSmith, wxWidgets 3.1.3] [Solved]

Post by var_null » Wed Mar 18, 2020 7:08 am

Hello, I used wxSmith to create the GUI for my program

Everything was fine until I added a bitmap (staticboxsizer_Logo--> imagepanel_logo --> staticbitmap_logo):


Now I'm getting the following errors:

Code: Select all

/bin/sh -c 'make -j4 -e -f  Makefile'
----------Building project:[ file - Debug ]----------
make[1]: Entering directory '/home/<username>/CProjects/Workspace/file'
/usr/bin/clang++  -c  "/home/<username>/CProjects/Workspace/file/file__Main.cpp" -g -O0 -Wall -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.1-unofficial -I/usr/include/wx-3.1-unofficial -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread   -o ./Debug/file__Main.cpp.o -I. -I.
/home/<username>/CProjects/Workspace/file/file__Main.cpp:209:27: error: allocating an object of abstract class type 'wxImageHandler'
    imagepanel_Logo = new wxImageHandler(Panel1, ID_IMAGEPANEL1, wxDefaultPosition, wxSize(250,46), wxTAB_TRAVERSAL, _T("ID_IMAGEPANEL1"));
                          ^
/usr/include/wx-3.1-unofficial/wx/image.h:154:18: note: unimplemented pure virtual method 'DoCanRead' in 'wxImageHandler'
    virtual bool DoCanRead( wxInputStream& stream ) = 0;
                 ^
/home/<username>/CProjects/Workspace/file/file__Main.cpp:210:22: error: no member named 'SetStretch' in 'wxImageHandler'
    imagepanel_Logo->SetStretch(false);
    ~~~~~~~~~~~~~~~  ^
/home/<username>/CProjects/Workspace/file/file__Main.cpp:211:29: error: no matching constructor for initialization of 'wxStaticBitmap'
    staticbitmap_Logo = new wxStaticBitmap(imagepanel_Logo, ID_STATICBITMAP1, wxBitmap(wxImage(_T("/mnt/data/VMware/VM-Shared/file++_Logo.png"))), wxPoint(1,-2), wxDefaultSize, 0, _T("ID_STATICBITMAP1"));
                            ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/wx-3.1-unofficial/wx/gtk/statbmp.h:22:5: note: candidate constructor not viable: no known conversion from 'wxImageHandler *' to 'wxWindow *' for 1st argument
    wxStaticBitmap( wxWindow *parent,
    ^
/usr/include/wx-3.1-unofficial/wx/gtk/statbmp.h:18:24: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 7 were provided
class WXDLLIMPEXP_CORE wxStaticBitmap : public wxStaticBitmapBase
                       ^
/usr/include/wx-3.1-unofficial/wx/gtk/statbmp.h:21:5: note: candidate constructor not viable: requires 0 arguments, but 7 were provided
    wxStaticBitmap();
    ^
/home/<username>/CProjects/Workspace/file/file__Main.cpp:212:26: error: no matching member function for call to 'Add'
    staticboxsizer_Logo->Add(imagepanel_Logo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    ~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/wx-3.1-unofficial/wx/sizer.h:1168:10: note: candidate function not viable: no known conversion from 'wxImageHandler *' to 'wxWindow *' for 1st argument
wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1174:10: note: candidate function not viable: no known conversion from 'wxImageHandler *' to 'wxSizer *' for 1st argument
wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1180:10: note: candidate function not viable: no known conversion from 'wxImageHandler *' to 'int' for 1st argument
wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1198:10: note: candidate function not viable: requires 3 arguments, but 4 were provided
wxSizer::Add( int width, int height, const wxSizerFlags& flags )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1186:10: note: candidate function not viable: requires 2 arguments, but 4 were provided
wxSizer::Add( wxWindow *window, const wxSizerFlags& flags )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1192:10: note: candidate function not viable: requires 2 arguments, but 4 were provided
wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
         ^
/usr/include/wx-3.1-unofficial/wx/sizer.h:1162:10: note: candidate function not viable: requires single argument 'item', but 4 arguments were provided
wxSizer::Add( wxSizerItem *item )
         ^
4 errors generated.
make[1]: *** [file.mk:95: Debug/file__Main.cpp.o] Error 1
make[1]: Leaving directory '/home/<username>/CProjects/Workspace/file'
make: *** [Makefile:5: All] Error 2
====4 errors, 11 warnings====

Hope someone can tell me what I need to edit so I can compile my program

Regards
Last edited by var_null on Wed Mar 18, 2020 8:14 am, edited 3 times in total.

Kvaz1r
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 216
Joined: Tue Jun 07, 2016 1:07 pm

Re: error: allocating an object of abstract class type 'wxImageHandler' [wxSmith, wxWidgets 3.1.3]

Post by Kvaz1r » Wed Mar 18, 2020 7:32 am

wxImageHandler doesn't have such constructor, moreover it's an abstract class so it's a bug of wxSmith. Try to replace with wxStaticBitmap.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2469
Joined: Sun Jan 03, 2010 5:45 pm

Re: error: allocating an object of abstract class type 'wxImageHandler' [wxSmith, wxWidgets 3.1.3]

Post by PB » Wed Mar 18, 2020 7:33 am

Please check the wxImageHandler documentation and you will see what is wrong. In short, wxImageHandler is not a control.

I do not use wxSmith so I do not know how it is possible that it let you generate such code. My guess is you actually wanted wxImagePanel (I assume wsStaticBitmap was for some reason not good enough?).

I understand that being new to C++, wxWidgets, and the IDE all at once must be difficult and frustrating but I would still recommend being more curious. E.g., here you would learn what the issue is had you checked what wxImageHandler is.

var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

Re: error: allocating an object of abstract class type 'wxImageHandler' [wxSmith, wxWidgets 3.1.3]

Post by var_null » Wed Mar 18, 2020 8:05 am

Hello, thanks for your reply

In fact wxSmith generated

Code: Select all

#include "wx/wxImagePanel.h"

...

wxImagePanel* imagepanel_Logo;

...

imagepanel_Logo = new wxImagePanel(Panel1, ID_IMAGEPANEL1, wxDefaultPosition, wxSize(250,46), wxTAB_TRAVERSAL, _T("ID_IMAGEPANEL1"));
    imagepanel_Logo->SetStretch(false);
And the compiler suggested me replacing "#include "wx/wxImagePanel.h"" to "#include "wx/wx.h"" and replacing wxImagePanel with wxImageHandler

Thought wxImagePanel was needed to use the wxStaticBitmap

Deleted wxImagePanel and left only the wxStaticBitmap inside the wxStaticBoxSizer, now the program compiles without errors

Post Reply