'wxGenericDirCtrl' does not name a type ?

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

'wxGenericDirCtrl' does not name a type ?

Post by vanarieleyen »

I have a problem with wxGenericDirCtrl.

When I create a new project in codeblocks, add the control to the form and compile it I get the following error:

||=== Build: Debug in preview (compiler: GNU GCC Compiler) ===|
C:\dev\preview\previewMain.h|185|error: 'wxGenericDirCtrl' does not name a type; did you mean 'wxGenericDirButton'?|
C:\dev\preview\previewMain.cpp||In constructor 'previewFrame::previewFrame(wxWindow*, wxWindowID)':|
C:\dev\preview\previewMain.cpp|92|error: 'GenericDirCtrl1' was not declared in this scope|
C:\dev\preview\previewMain.cpp|92|note: suggested alternative: 'DirPickerCtrl1'|
C:\dev\preview\previewMain.cpp|92|error: expected type-specifier before 'wxGenericDirCtrl'|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 25 second(s)) ===|

From this error I understand that the class wxGenericDirCtrl is not implemented, so the first thing to do is check the header.
The header is there and the contents looks OK.

When I do this test in Linux however, there are no problems at all (the problem arises in Windows).
Is this a known issue or am I doing something wrong?
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 'wxGenericDirCtrl' does not name a type ?

Post by doublemax »

That should work. The #include is "wx/generic/dirctrlg.h" ?
Is it included inside previewMain.h so that the class is known there?
Use the source, Luke!
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: 'wxGenericDirCtrl' does not name a type ?

Post by vanarieleyen »

No, the include is wx/dirctrl.h
I can open this file and it shows a line that includes wx/generic/dirctrlg.h

This file I can also open and has the declaration of wxGenericDirCtrl, so I guess it should be no problem.

However I now see that the constructor line is:
class WXDLLIMPEXP_CORE wxGenericDirCtrl: public wxControl

This 'WXDLLIMPEXP_CORE' gets me to think that I need to link a dll that it perhaps can't find. On the other hand, the error are compiler errors and not linker errors...
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 'wxGenericDirCtrl' does not name a type ?

Post by doublemax »

Can you post the content of previewMain.h?

You can ignore the WXDLLIMPEXP_CORE. This macro will be redefined depending on the current build / configuration.
Use the source, Luke!
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: 'wxGenericDirCtrl' does not name a type ?

Post by vanarieleyen »

This is previewMain.h

Code: Select all

/***************************************************************
 * Name:      previewMain.h
 * Purpose:   Defines Application Frame
 * Author:    Arie van Leyen ()
 * Created:   2019-09-05
 * Copyright: Arie van Leyen ()
 * License:
 **************************************************************/

#ifndef PREVIEWMAIN_H
#define PREVIEWMAIN_H

//(*Headers(previewFrame)
#include <wx/dirctrl.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
//*)

class previewFrame: public wxFrame
{
    public:

        previewFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~previewFrame();

    private:

        //(*Handlers(previewFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        //*)

        //(*Identifiers(previewFrame)
        static const long ID_GENERICDIRCTRL1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(previewFrame)
        wxGenericDirCtrl* GenericDirCtrl1;
        wxStatusBar* StatusBar1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // PREVIEWMAIN_H

and to make it complete, here is previewMain.cpp

Code: Select all

/***************************************************************
 * Name:      previewMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Arie van Leyen ()
 * Created:   2019-09-05
 * Copyright: Arie van Leyen ()
 * License:
 **************************************************************/

#include "previewMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(previewFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(previewFrame)
const long previewFrame::ID_GENERICDIRCTRL1 = wxNewId();
const long previewFrame::idMenuQuit = wxNewId();
const long previewFrame::idMenuAbout = wxNewId();
const long previewFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(previewFrame,wxFrame)
    //(*EventTable(previewFrame)
    //*)
END_EVENT_TABLE()

previewFrame::previewFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(previewFrame)
    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    GenericDirCtrl1 = new wxGenericDirCtrl(this, ID_GENERICDIRCTRL1, wxEmptyString, wxPoint(112,256), wxDefaultSize, 0, wxEmptyString, 0, _T("ID_GENERICDIRCTRL1"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&previewFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&previewFrame::OnAbout);
    //*)
}

previewFrame::~previewFrame()
{
    //(*Destroy(previewFrame)
    //*)
}

void previewFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void previewFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 'wxGenericDirCtrl' does not name a type ?

Post by doublemax »

Move #include <wx/dirctrl.h> to the end of the #includes or include <wx/wx.h> first.

Code: Select all

// #include <wx/wx.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
#include <wx/dirctrl.h>
Use the source, Luke!
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: 'wxGenericDirCtrl' does not name a type ?

Post by vanarieleyen »

Max, you are a genius!

I would never have come up with that solution.
However, I think that it shouldn't matter and if it does, it should be mentioned in the documentation...

But anyway, I am happy that it is working :D
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 'wxGenericDirCtrl' does not name a type ?

Post by doublemax »

vanarieleyen wrote: Thu Sep 05, 2019 6:51 amHowever, I think that it shouldn't matter and if it does, it should be mentioned in the documentation...
I think this is more a CodeBlocks than a wxWidgets problem. I think wx/wx.h should be the first include everywhere instead of relying that another header file will include it anyway.

The problem is, without including wx/wx.h, setup.h will not be included and the wxUSE_DIRDLG define that's checked at the beginning of dirctrlg.h, will be undefined. And therefore everything else in that file will be invisible to the compiler.
Use the source, Luke!
vanarieleyen
Knows some wx things
Knows some wx things
Posts: 47
Joined: Thu Aug 29, 2019 3:55 am
Location: China, Shenzhen

Re: 'wxGenericDirCtrl' does not name a type ?

Post by vanarieleyen »

That is a very good tip! I will remember this.