Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Petit problème avec la librairie graphique wxWidget

1 réponse
Avatar
Sylvain SAUREL
Bonjour,

A la recherche d'un solution pour faire une interface graphique pour un pro=
gramme =C3=A9crit en C++, j'ai trouv=C3=A9 la librairie wxWidget qui a l'av=
antage de se porter assez facilement sous Windows apparemment.

Je suis sur une Debian 3.1 sous linux. J'ai donc t=C3=A9l=C3=A9charg=C3=A9 =
les packages n=C3=A9cessaires =C3=A0 la librairie wxWidget.

J'ai trouv=C3=A9 un petit tutorial sur le site www.wxwidgets.org permettant=
de faire un petit "Hello World" avec la librairie histoire de voir si j'av=
ais tout bien install=C3=A9.

Le tutorial est =C3=A0 cette adresse :=20

www.wxwidgets.org/hello.htm


J'ai donc cr=C3=A9e un fichier hworld.cpp comme expliqu=C3=A9 dans le tutor=
ial.
Je compile avec la ligne suivante comme expliqu=C3=A9 dans le tutorial touj=
ours :=20


g++ hworld.cpp `wx-config --libs` `wx-config --cxxflags` -o hworld


J'obtiens ces erreurs :


$ g++ hworld.cpp `wx-config --libs` `wx-config --cxxflags` -o hworld
hworld.cpp:9: error: base class `wxFrame' has incomplete type
hworld.cpp:11: error: erreur d'analyse syntaxique before `&' token
hworld.cpp:13: error: `wxCommandEvent' was not declared in this scope
hworld.cpp:13: error: `event' was not declared in this scope
hworld.cpp:13: error: invalid data member initialization
hworld.cpp:13: error: (use `=3D' to initialize static data members)
hworld.cpp:13: error: variable or field `OnQuit' declared void
hworld.cpp:14: error: `wxCommandEvent' was not declared in this scope
hworld.cpp:14: error: `event' was not declared in this scope
hworld.cpp:14: error: invalid data member initialization
hworld.cpp:14: error: variable or field `OnAbout' declared void
hworld.cpp:26: error: incomplete type `wxFrame' does not have member `
sm_eventTable'
hworld.cpp:27: error: `wxCommandEventFunction' was not declared in this sco=
pe
hworld.cpp:28: error: `wxCommandEventFunction' was not declared in this sco=
pe
hworld.cpp: Dans function =C2=AB wxApp* wxCreateApp() =C2=BB:
hworld.cpp:31: error: cannot allocate an object of type `MyApp'
hworld.cpp:31: error: because the following virtual functions are abstrac=
t:
/usr/include/wx/app.h:131: error: virtual int wxAppBase::OnRun()
hworld.cpp: Dans member function =C2=AB virtual bool MyApp::OnInit() =C2=BB=
:
hworld.cpp:36: error: invalid use of undefined type `struct wxPoint'
/usr/include/wx/utils.h:46: error: forward declaration of `struct wxPoint'
hworld.cpp:36: error: `wxSize' undeclared (first use this function)
hworld.cpp:36: error: (Each undeclared identifier is reported only once for
each function it appears in.)
hworld.cpp:37: error: `Show' undeclared (first use this function)
hworld.cpp:38: error: `SetTopWindows' undeclared (first use this function)
hworld.cpp: At global scope:
hworld.cpp:42: error: erreur d'analyse syntaxique before `&' token
hworld.cpp:45: error: erreur de syntaxe before `->' token
hworld.cpp:46: error: erreur de syntaxe before `->' token
hworld.cpp:47: error: erreur de syntaxe before `->' token
hworld.cpp:48: error: erreur de syntaxe before `*' token
hworld.cpp:49: error: erreur de syntaxe before `->' token
hworld.cpp:50: error: `menuBar' was not declared in this scope
hworld.cpp:50: error: le C++ ISO interdit la d=C3=A9claration de =C2=AB Set=
MenuBar =C2=BB sans
type
hworld.cpp:50: error: `int MyFrame::SetMenuBar' is not a static member of `
class MyFrame'
hworld.cpp:51: error: le C++ ISO interdit la d=C3=A9claration de =C2=AB Cre=
ateStatusBar =C2=BB
sans type
hworld.cpp:52: error: le C++ ISO interdit la d=C3=A9claration de =C2=AB Set=
StatusText =C2=BB
sans type
hworld.cpp:52: error: `int MyFrame::SetStatusText' is not a static member o=
f `
class MyFrame'
hworld.cpp:52: error: conversion invalide de =C2=AB const char* =C2=BB vers=
=C2=AB int =C2=BB
hworld.cpp:53: error: erreur d'analyse syntaxique before `}' token
hworld.cpp:55: error: `wxCommandEvent' was not declared in this scope
hworld.cpp:55: error: erreur d'analyse syntaxique before `)' token
hworld.cpp:56: error: no `void MyFrame::OnQuit(...)' member function declar=
ed
in class `MyFrame'
hworld.cpp:56: error: declaration of `void MyFrame::OnQuit(...)'
hworld.cpp:13: error: conflicts with previous declaration `int MyFrame::OnQ=
uit'
hworld.cpp: Dans member function =C2=AB void MyFrame::OnQuit(...) =C2=BB:
hworld.cpp:57: error: `Close' undeclared (first use this function)
hworld.cpp: At global scope:
hworld.cpp:60: error: `wxCommandEvent' was not declared in this scope
hworld.cpp:60: error: erreur d'analyse syntaxique before `)' token
hworld.cpp:61: error: no `void MyFrame::OnAbout(...)' member function decla=
red
in class `MyFrame'
hworld.cpp:61: error: declaration of `void MyFrame::OnAbout(...)'
hworld.cpp:14: error: conflicts with previous declaration `int MyFrame::OnA=
bout
'
hworld.cpp: Dans member function =C2=AB void MyFrame::OnAbout(...) =C2=BB:
hworld.cpp:62: error: `wxMessageBox' undeclared (first use this function)



et voici le contenu de hworld.cpp :


#include "wx/wx.h"

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

class MyFrame: public wxFrame
{
=09public:
=09=09MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size=
);
=09=09
=09=09void OnQuit(wxCommandEvent& event);
=09=09void OnAbout(wxCommandEvent& event);
=09=09
=09=09DECLARE_EVENT_TABLE();
=09=09
};=20

enum
{
ID_Quit=3D1,
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()
{
=09MyFrame *frame =3D new MyFrame("Hello World",wxPoint(50,50),wxSize(450,3=
40));
=09frame->Show(TRUE);
=09SetTopWindows(frame);
=09return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& s=
ize): wxFrame((wxFrame *)NULL,-1,title,pos,size)
{
=09wxMenu *menuFile =3D new wxMenu;
=09menuFile->Append(ID_About,"&About...");
=09menuFile->AppendSeparator();
=09menuFile->Append(ID_Quit,"E&xit");
=09wxMenuBar *menuBar =3D new wxMenuBar;
=09menuBar->Append(menuFile,"&File");
=09SetMenuBar(menuBar);
=09CreateStatusBar();
=09SetStatusText("Welcome to wxWidgets!");
}

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

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



J'ai du mal installer quelque chose mais je vois pas quoi.
Pourtant quand je fais :

$ wx-config --libs
-pthread -lwx_base-2.4
$ wx-config --cxxflags
-I/usr/lib/wx/include/base-2.4 -D_FILE_OFFSET_BITS=3D64 -D_LARGE_FILES

=C3=A7a point bien au bon endroit je pense.
J'ai gcc 3.3.5 et wx 2.4

Si quelqu'un sait ce que j'ai mal fait dans l'installation ou a d=C3=A9j=C3=
=A0 eu ce m=C3=AAme probl=C3=A8me, =C3=A7a serait
sympa qu'il m'explique ce qu'il faut faire.

Merci d'abord.

1 réponse

Avatar
matthias
Sylvain SAUREL wrote:

Bonjour,




Bonjour,

A la recherche d'un solution pour faire une interface graphique pour un programme écrit en C++, j'ai trouvé la librairie wxWidget qui a l'avantage de se porter assez facilement sous Windows apparemment.

Je suis sur une Debian 3.1 sous linux. J'ai donc téléchargé les packages nécessaires à la librairie wxWidget.

J'ai trouvé un petit tutorial sur le site www.wxwidgets.org permettant de faire un petit "Hello World" avec la librairie histoire de voir si j'avais tout bien installé.

Le tutorial est à cette adresse :

www.wxwidgets.org/hello.htm

J'ai donc crée un fichier hworld.cpp comme expliqué dans le tutorial.
Je compile avec la ligne suivante comme expliqué dans le tutorial toujours :

g++ hworld.cpp `wx-config --libs` `wx-config --cxxflags` -o hworld

J'obtiens ces erreurs :

$ g++ hworld.cpp `wx-config --libs` `wx-config --cxxflags` -o hworld
hworld.cpp:9: error: base class `wxFrame' has incomplete type




[...]

J'ai du mal installer quelque chose mais je vois pas quoi.
Pourtant quand je fais :

$ wx-config --libs
-pthread -lwx_base-2.4
$ wx-config --cxxflags
-I/usr/lib/wx/include/base-2.4 -D_FILE_OFFSET_BITSd -D_LARGE_FILES

ça point bien au bon endroit je pense.
J'ai gcc 3.3.5 et wx 2.4

Si quelqu'un sait ce que j'ai mal fait dans l'installation ou a déjà eu ce même problème, ça serait
sympa qu'il m'explique ce qu'il faut faire.

Merci d'abord.





Si tu utilises le package "libwxgtk2.4-dev" cela devrait marcher.

Tu remarqueras la différence de sortie de wx-config --libs et wx-config
--cxxflags.
( cf: man wx-config )

Je ne peux pas t'en dire plus pour l'instant, car je n'ai jamais
dévellopé avec cette lib.
Tu auras desoins de chercher des précisions sur la nécessité de
librairies supplémentaires pour l'affichage,
en l'occurence la gestion des wxFrame, qu'ici on résout avec gtk... ( il
y a peut-être d'autres solutions ).


matthias

ps: Tu feras attention ligne 38: c'est la fonction "SetTopWindow" ( sans
's' ). ;)


--
Pensez