2010-10-17 18 views
0

D'accord, j'ai rencontré un problème vraiment bizarre.WxWidgets: Troubling Callling wxFrame ConstructorE

J'ai un programme wxWidgets qui a deux cadres, un principal, et un secondaire.

Le principal a un bouton qui appelle le second à ouvrir.

J'ai eu des problèmes avec l'appel d'une classe dérivée de la classe de la deuxième wxframe, donc j'ai déplacé la déclaration/implémentation de la classe avant la classe pour l'image principale.

Maintenant, je reçois une erreur de compilation.

Voici le fichier d'en-tête contenant les classes wxFrame dérivées:

/*************************************************************** 
* Name:  NUEMain.h 
* Purpose: Defines Application Frame 
* Author: Cypher() 
* Created: 2010-10-02 
* Copyright: Cypher() 
* License: 
**************************************************************/ 
#include "System.h" 
#ifndef NUEMAIN_H 
#define NUEMAIN_H 


#include "NUEApp.h" 
#include "GUIFrame.h" 
#include "System.h" 
#include <wx/wx.h> 


class NUEAsset : public AssetEd 
{ 
    public: 
     NUEAsset(wxFrame *frame){} <-- Error here 
     ~NUEAsset(){}; 

     //Xml object 
     XmlO SysX; 
    private: 
     virtual void OnClose(wxCloseEvent& event); 
     virtual void OnQuit(wxCommandEvent& event); 
     virtual void OnAbout(wxCommandEvent& event); 

     //Open File Event 
     virtual void OpenFile(wxCommandEvent& event){ 
      wxFileDialog* OpenDialog = new wxFileDialog(
      this, _("Choose a file to open"), wxEmptyString, wxEmptyString,_("XML Files (*.xml)|*.xml"),wxFD_OPEN, wxDefaultPosition); 

      // Creates a "open file" dialog with 4 file types 
      if (OpenDialog->ShowModal() == wxID_OK) // if the user click "Open" instead of "Cancel" 
      { 
       //Change Statusbar to display path of opened file 
       SetStatusText(OpenDialog->GetPath(),0); 

       //Set m_SysListBox contents to names from ssys.xml 
       SysX.load(OpenDialog->GetPath()); 
       Asset assetsys; 
       //Start adding names to m_SysListbox 
       //Pointer to system 
       for(int i = 0; i < SysX.Sys.size(); i++){ 
        assetsys = SysX.Sys.at(i); 
        //Get name of system as string 
        //Convert name from string to wxString 
        m_SysListBox->AppendString(assetsys.name); 
       } 
       // MainEditBox->LoadFile(CurrentDocPath); //Opens that file 
      } 
       //SetTitle(wxString("Edit - ") <<OpenDialog->GetFilename()); // Set the Title to reflect the file open 


     // Clean up after ourselves 
     OpenDialog->Destroy(); 


     } 
     //Handle clicking on a system 
     virtual void sys_click(wxCommandEvent& event) { 
      //Get the index of the selected item 
      int ind; 
      ind = m_SysListBox->GetSelection(); 

      wxString tmp_sys_nam; 
      wxString tmp_x; 
      wxString tmp_y; 

      tmp_sys_nam = SysX.Sys.at(ind).name; 
      tmp_x << SysX.Sys.at(ind).x_pos; 
      tmp_y << SysX.Sys.at(ind).y_pos; 

      //Set the asset name listbox 
      m_textPNAME->ChangeValue(tmp_sys_nam); 

      //Set the X_pos listbox 
      m_textRadius->ChangeValue(tmp_x); 

      //Set the Y_pos listbox 
      m_textStars->ChangeValue(tmp_y); 

     } 
}; 


class NUEFrame: public GUIFrame 
{ 
    public: 
     NUEFrame(wxFrame *frame); 
     ~NUEFrame(); 

     //Xml object 
     XmlO SysX; 
    private: 
     virtual void OnClose(wxCloseEvent& event); 
     virtual void OnQuit(wxCommandEvent& event); 
     virtual void OnAbout(wxCommandEvent& event); 

     //Launch Asset Editor 
     virtual void launch_asset_ed(wxCommandEvent& event) { 
      NUEAsset* asset_ed_frame = new NUEAsset(0L); 
      asset_ed_frame->SetIcon(wxICON(aaaa)); // To Set App Icon 
      asset_ed_frame->Show(); 

     } 

     //Open File Event 
    /* virtual void OpenFile(wxCommandEvent& event){ 
      wxFileDialog* OpenDialog = new wxFileDialog(
      this, _("Choose a file to open"), wxEmptyString, wxEmptyString,_("XML Files (*.xml)|*.xml"),wxFD_OPEN, wxDefaultPosition); 

      // Creates a "open file" dialog with 4 file types 
      if (OpenDialog->ShowModal() == wxID_OK) // if the user click "Open" instead of "Cancel" 
      { 
       //Change Statusbar to display path of opened file 
       SetStatusText(OpenDialog->GetPath(),0); 

       //Set m_SysListBox contents to names from ssys.xml 
       SysX.load(OpenDialog->GetPath()); 
       Asset assetsys; 
       //Start adding names to m_SysListbox 
       //Pointer to system 
       for(int i = 0; i < SysX.Sys.size(); i++){ 
        assetsys = SysX.Sys.at(i); 
        //Get name of system as string 
        //Convert name from string to wxString 
        m_SysListBox->AppendString(assetsys.name); 
       } 
       // MainEditBox->LoadFile(CurrentDocPath); //Opens that file 
      } 
       //SetTitle(wxString("Edit - ") <<OpenDialog->GetFilename()); // Set the Title to reflect the file open 


     // Clean up after ourselves 
     OpenDialog->Destroy(); 


     } */ 
     //Handle clicking on a system 
    /* virtual void sys_click(wxCommandEvent& event) { 
      //Get the index of the selected item 
      int ind; 
      ind = m_SysListBox->GetSelection(); 

      wxString tmp_sys_nam; 
      wxString tmp_x; 
      wxString tmp_y; 

      tmp_sys_nam = SysX.Sys.at(ind).name; 
      tmp_x << SysX.Sys.at(ind).x_pos; 
      tmp_y << SysX.Sys.at(ind).y_pos; 

      //Set the asset name listbox 
      m_textPNAME->ChangeValue(tmp_sys_nam); 

      //Set the X_pos listbox 
      m_textRadius->ChangeValue(tmp_x); 

      //Set the Y_pos listbox 
      m_textStars->ChangeValue(tmp_y); 

     }*/ 
}; 

#endif // NUEMAIN_H 

Voici l'en-tête à partir de laquelle les classes dérivent:

/////////////////////////////////////////////////////////////////////////// 
// C++ code generated with wxFormBuilder (version Sep 8 2010) 
// http://www.wxformbuilder.org/ 
// 
// PLEASE DO "NOT" EDIT THIS FILE! 
/////////////////////////////////////////////////////////////////////////// 

#ifndef __GUIFrame__ 
#define __GUIFrame__ 

#include <wx/string.h> 
#include <wx/button.h> 
#include <wx/gdicmn.h> 
#include <wx/font.h> 
#include <wx/colour.h> 
#include <wx/settings.h> 
#include <wx/sizer.h> 
#include <wx/bitmap.h> 
#include <wx/image.h> 
#include <wx/icon.h> 
#include <wx/menu.h> 
#include <wx/frame.h> 
#include <wx/stattext.h> 
#include <wx/listbox.h> 
#include <wx/textctrl.h> 
#include <wx/toolbar.h> 
#include <wx/statusbr.h> 

/////////////////////////////////////////////////////////////////////////// 

#define idMenuQuit 1000 
#define idMenuAbout 1001 

/////////////////////////////////////////////////////////////////////////////// 
/// Class GUIFrame 
/////////////////////////////////////////////////////////////////////////////// 
class GUIFrame : public wxFrame 
{ 
private: 

protected: 

    wxButton* m_buttonAsset; 
    wxButton* m_buttonShip; 


    wxButton* m_buttonTech; 
    wxButton* m_buttonOutfit; 

    wxMenuBar* m_menubar2; 
    wxMenu* m_file; 

    // Virtual event handlers, overide them in your derived class 
    virtual void OnClose(wxCloseEvent& event) { event.Skip(); } 
    virtual void launch_asset_ed(wxCommandEvent& event) { event.Skip(); } 


public: 

    GUIFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("NUE v0.0.1a"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(-1,-1), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL); 
    ~GUIFrame(); 

}; 

/////////////////////////////////////////////////////////////////////////////// 
/// Class AssetEd 
/////////////////////////////////////////////////////////////////////////////// 
class AssetEd : public wxFrame 
{ 
private: 

protected: 
    wxMenuBar* mbar; 
    wxMenu* fileMenu; 
    wxMenu* helpMenu; 
    wxStaticText* m_staticTextSysboxlabel; 
    wxListBox* m_SysListBox; 
    wxStaticText* m_staticParamslabel; 
    wxStaticText* m_staticText4; 
    wxTextCtrl* m_textPNAME; 
    wxStaticText* m_staticText5; 
    wxTextCtrl* m_textRadius; 
    wxStaticText* m_staticText6; 
    wxTextCtrl* m_textStars; 
    wxStaticText* m_staticText61; 
    wxTextCtrl* m_textInterference; 
    wxStaticText* m_staticText611; 
    wxStaticText* m_staticText612; 
    wxTextCtrl* m_textPosX; 
    wxStaticText* m_staticText6121; 
    wxTextCtrl* m_textPosY; 
    wxStaticText* m_staticLinksLabel; 
    wxListBox* m_SysHyperlinkslist; 
    wxToolBar* m_toolBar1; 
    wxStatusBar* statusBar; 

    // Virtual event handlers, overide them in your derived class 
    virtual void OpenFILE(wxCommandEvent& event) { event.Skip(); } 
    virtual void OnQuit(wxCommandEvent& event) { event.Skip(); } 
    virtual void OnAbout(wxCommandEvent& event) { event.Skip(); } 
    virtual void sys_click(wxCommandEvent& event) { event.Skip(); } 


public: 

    AssetEd(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(915,500), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL); 
    ~AssetEd(); 

}; 

#endif //__GUIFrame__ 

C'est l'erreur que je reçois: \ NUEMain.h | 23 | error: pas de fonction correspondante pour l'appel à 'AssetEd :: AssetEd()' |

Ceci est une erreur appelant le constructeur dans la classe parent, mais j'ai simplement copié la façon dont cela a été fait pour le cadre d'origine, qui a bien fonctionné.

Quoi de neuf?

EDIT 1:

accord, je remplacé

NUEAsset(wxFrame *frame){} 

avec

NUEAsset(wxFrame *frame): AssetEd(frame){} 

et il échoue maintenant à l'étape de liaison avec l'erreur suivante:

)]+0x7e)||undefined reference to `vtable for NUEAsset'| 

Je ne peux pas faire de h eads ou queues de cette erreur.

EDIT 2:

Oh, et je continue à avoir cet avertissement aussi, mais moi-même avons été l'ignorer. Cela pourrait-il être lié:

||warning: auto-importing has been activated without --enable-auto-import specified on the command line.| 

EDIT 3: Je pense que je l'ai résolu le problème en utilisant les informations ci-dessous et quelques recherches.

Il s'est avéré que je définissais certains événements pour une trame qui n'avait plus ces événements.

Modifié les defs, et cela semble fonctionner maintenant.

Répondre

1

AssetEd n'a pas de constructeur par défaut. Si vous définissez votre propre constructeur, le constructeur par défaut ne sera pas implicitement fourni.

Le problème est que l'objet de base d'une classe dérivée doit être construit d'une manière ou d'une autre. Si vous n'appelez pas un constructeur approprié de la liste d'initialisation, le constructeur par défaut sera utilisé implicitement.

NUEAsset doit simplement appeler le constructeur de la classe de base avec des arguments appropriés, par exemple

NUEAsset(wxFrame *frame): Asset(frame) {} 
+0

Bon, maintenant ça devient une erreur vraiment bizarre:)] + 0x7E) || undefined reference to 'vtable pour NUEAsset » | – Biosci3c

+0

Cela arrive parfois, et je ne sais pas pourquoi. Il n'identifie même pas l'endroit dans le dossier d'en-tête où le problème est. Aussi, encore plus bizarre, c'est le fait que c'est la même manière que l'autre frame le fait (sans appeler le constructeur par défaut, et ça marche bien). – Biosci3c