wxWidgets & Visual C++ 2005 Express

Pagina: 1
Acties:

  • microchip
  • Registratie: Maart 2004
  • Laatst online: 29-05-2021
Ik wil dus beginnen met het schrijven van programma's met wxWidgets. In het begin gebruikte ik altijd DevC++ maar omdat het compilen hier ZO langzaam ging, heb ik het maar opgegeven. Nu probeer ik het met Visual C++ 2005 Express omdat het een snellere compiler schijnt te zijn. Ik heb wxWidgets gecompiled, en dat liep vrij goed (afgezien van een depreciated warning hier en daar). Toen heb ik alle headers en libs gekopieerd naar VC++'s mappen. Nu probeer ik een simpel programmatje te compilen, maar krijg ik de error

"e:\my documents\visual studio 2005\projects\wxtest\wxtest\wxtest.cpp(46) : error C2664: 'MyFrame::MyFrame(const wxString &,const wxPoint &,const wxSize &)' : cannot convert parameter 1 from 'const char [12]' to 'const wxString &'
Reason: cannot convert from 'const char [12]' to 'const wxString'"

En dit dan paar keer, telkens als ik een string als parameter mee wil zenden.

C++:
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <wx/wx.h>

class MyApp: public wxApp
{
    virtual bool OnInit();
};

class MyFrame: public wxFrame
{
public:

    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

    DECLARE_EVENT_TABLE()
};

enum
{
    ID_Quit = 1,
    ID_About,
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(ID_Quit, MyFrame::OnQuit)
    EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame("Hello World", wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
} 

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
    wxMenu *menuFile = new wxMenu;

    menuFile->Append( ID_About, "&About..." );
    menuFile->AppendSeparator();
    menuFile->Append( ID_Quit, "E&xit" );

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, "&File" );

    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText( "Welcome to wxWindows!" );
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(TRUE);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxMessageBox("This is a wxWindows Hello world sample",
        "About Hello World", wxOK | wxICON_INFORMATION, this);
}

  • whoami
  • Registratie: December 2000
  • Laatst online: 23:12
Tja, da's een kwestie van foutmeldingen lezen en interpreteren.
Blijkbaar verwacht die method geen 'string', maar een wxString, wat dus een data-type zal zijn binnen die wxWidgets lib.

https://fgheysels.github.io/


  • microchip
  • Registratie: Maart 2004
  • Laatst online: 29-05-2021
Maar is er ook een manier om dit zonder cast op te lossen? Ik vind het namelijk heel irritant om telkens voor elke string (wxString) te moeten zetten...

  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 09-04 22:08
Op zich zou er een impliciete constructor moeten zijn die een char const* accepteert (en zoals je weet is er een conversie char const[] -> char const*), dus die cast zou niet nodig moeten zijn. Sowieso denk ik dat die cast ook illegaal is, als de de impliciete conversie dat is. Het enige wat ik kan bedenken is dat je wxWidgets voor unicode hebt gebouwd. In dat geval moet je een wide string literal gebruiken, L"" (wchar_t const[]). In dat geval lijkt het me redelijk dat de widening conversie die je nodig hebt expliciet is, maar geeft VC2005 dan die foutmelding?

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • microchip
  • Registratie: Maart 2004
  • Laatst online: 29-05-2021
Hmm dat zou best kunnen, want met 'L' ervoor werkt het ook. Even kijken of ik het kan builden zonder unicode...

Ik heb er ook dit over gevonden: http://wiki.wxwidgets.org/wiki.pl?WxString. Staat ook dat het met unicode support te maken heeft. Wat is het voordeel van Unicode eigenlijk? Als al je gebruikte karakters al in ASCII zitten?

[edit]
Opnieuw gecompiled, als Release dit keer, zonder unicode, en het werkt nog steeds niet zonder de macro...

[ Voor 17% gewijzigd door microchip op 29-10-2005 15:53 ]


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 09-04 22:08
Geloof me: In ASCII zitten de karakters die je wilt niet. Euroteken? ASCII is tenslotte een American Standard.

Overigens: welke macro? L is geen macro!

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • microchip
  • Registratie: Maart 2004
  • Laatst online: 29-05-2021
De macro wxT was het geloof ik. Die zorgde ook dat de errors weggingen.

Maarja, kan erger dan overal een L voor zetten :) . Ik denk dat ik het zo maar laat...

[ Voor 39% gewijzigd door microchip op 30-10-2005 10:22 ]

Pagina: 1