XPM icon 'no conversion from "const unsigned char *[39] to "wxIcon" '

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
paddle
Knows some wx things
Knows some wx things
Posts: 43
Joined: Sat Oct 12, 2019 4:57 pm

XPM icon 'no conversion from "const unsigned char *[39] to "wxIcon" '

Post by paddle »

Hi guys,
I had a very annoying bug that is solved and I just wanted to document it here in case it happens to someone.

I was just trying to use some XPM icons for a treeCtrl as I did in a previous project. In short the code used :
myFrame.h :

Code: Select all

#include "wx/imaglist.h"
#include "icons/iconID.xpm"
#include "icons/iconIF.xpm"
#include "icons/iconAPP.xpm"
myFrame.cpp :

Code: Select all

MyFrame::MyFrame() : wxFrame(...)
{
    SetIcon(iconapp_xpm);
    createImageList(); 
    ...
}

void MyFrame::createImageList() {
    wxImageList* images = new wxImageList(16, 16, true);
    wxBusyCursor wait;

    images->Add(wxIcon(iconid_xpm));
    images->Add(wxIcon(iconif_xpm));

    ifTreeViewer->AssignImageList(images);
}
    
However it wasn't compiling. SetIcon() and wxIcon() weren't happy reporting
SetIcon error : no suitable constructor exist to convert from "const unsigned char *[39] to "wxIcon"
wxIcon error : no instance of constructor "wxIcon::wxIcon" matches the argument list argument types are: (const unsigned char *[39])
So after a lot of useless research, I found that the problem was the icon I generated using "Junior Icon Editor". I tried to reuse some other icons and the code was fine. Looking at the xpm code :
Non working XPM icon :

Code: Select all

/* XPM */ 
static const unsigned char * iconid_xpm[] = {...
Working XPM icon :

Code: Select all

/* XPM */ 
static const char *const iconidnok_xpm[] = {...
c5
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Feb 27, 2022 2:40 am

Re: XPM icon 'no conversion from "const unsigned char *[39] to "wxIcon" '

Post by c5 »

Good that you shared what fixed your issue. Convertio is great at converting image files to XPMs.
https://convertio.co/png-xpm/
Also just loading from disk :D
Post Reply