[SOLVED] ComboBox doesn't accept wxArrayString

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Arthas
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Dec 14, 2013 6:47 pm

[SOLVED] ComboBox doesn't accept wxArrayString

Post by Arthas » Thu Dec 19, 2013 11:58 pm

When I try to assign a wxArrayString to wxComboBox, as specified in the documentation (http://docs.wxwidgets.org/2.8/wx_wxarra ... stringctor), CodeLite returns this error:

C:/UnitTest++-1.3/foobar/foobar_frame.cpp:68:101: error: invalid conversion from 'wxArrayString*' to 'int' [-fpermissive]
C:/UnitTest++-1.3/foobar/foobar_frame.cpp:68:101: error: invalid conversion from 'int' to 'const wxString*' [-fpermissive]


This is the header file:

Code: Select all

#ifndef __FoobarFrame__
#define __FoobarFrame__

#include <stdio.h>
#include <wx/string.h>
#include <wx/arrstr.h>
#include <wx/init.h>
#include "wx/wx.h"
#include <wx/frame.h>
#include <wx/spinctrl.h>
#include <wx/textctrl.h>
#include <wx/listctrl.h>
#include <wx/combobox.h>

class FoobarFrame : public wxFrame {

private:
	void Initialize();
	void CreateMenuBar();
	
public:
	FoobarFrame(wxWindow* parent,
            wxWindowID id,
            const wxString& title,
            const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize,
            long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER);
	
	~FoobarFrame();
	DECLARE_EVENT_TABLE()
	
	
	wxArrayString *items;
	wxSpinCtrl *numericupdown;
	wxTextCtrl *nomegruppi;
	wxListCtrl *lc;
	wxComboBox *cb;
	
	
	void OnClose(wxCloseEvent &e);
	void OnQuit(wxCommandEvent &e);
	void Onbtn1(wxCommandEvent &e);
	
};
#endif // __FoobarFrame__
And the wxComboBox initialization:

Code: Select all

//ComboBox
	items = new wxArrayString();
	items->Add("foo");
	items->Add("bar");
	items->Add("blah");
	cb = new wxComboBox(panel, 7, wxEmptyString, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
I'm a beginner, so don't give too many things for granted
Last edited by Arthas on Fri Dec 20, 2013 12:26 am, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 14626
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: ComboBox doesn't accept wxArrayString

Post by doublemax » Fri Dec 20, 2013 12:19 am

wxComboBox(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "comboBox")
If you look at the wxComboBox ctor, it takes a reference to wxArrayString.

Code: Select all

items = new wxArrayString();
cb = new wxComboBox(panel, 7, wxEmptyString, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
But you are passing a pointer.

Try this:

Code: Select all

cb = new wxComboBox(panel, 7, wxEmptyString, wxDefaultPosition, wxDefaultSize, *items, wxCB_READONLY);
If you don't understand the difference, please consult a C++ book and read up on pointers and references.
Use the source, Luke!

Post Reply