wxDataViewCtrl implementation failure

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

wxDataViewCtrl implementation failure

Post by papillon68 »

Hello, I'd like to ask if there is a specific way to implement wxDataViewCtrl, as it is silently shutting down my application at startup just after its implementation.
Here is a summary of my wxFrame constructor where I build all the UI elements successfully (besides the wxDataViewCtrl):

Code: Select all

MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(500, 400))
{
......................
wxButton *myButton = new wxButton(this, wxID_ANY, wxT("New"), wxPoint(0, 0), wxSize(200, 40), 0, wxDefaultValidator, "myButton");
wxDataViewCtrl *listCtrl= new wxDataViewCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(300, 300), wxDV_NO_HEADER | wxDV_VARIABLE_LINE_HEIGHT); // shuts down application ???
}
Thanks.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl implementation failure

Post by doublemax »

Platform, wxWidgets version?

So when you comment out this one line, the program runs fine?

Are you running a debug build? If there is something wrong, it should crash, but not just close silently.

Does the "dataview" sample work for you?
Use the source, Luke!
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: wxDataViewCtrl implementation failure

Post by papillon68 »

Hello, first of all, thanks for the support, I really appreciate it.
Windows 10, MS VC++ 2015, WxWidgets 3.11. Commenting the line out the program runs fine, but I was using 3.11 debug libraries.
So now I switched to wxMSW-3.1.1_vc140_x64_Release libraries (so I'm using precompiled ones), and the linker throws unresolved external symbol on the wxDataViewCtrl (see below).
I'm probably missing a .dll that isn't provided with the archive file?

Code: Select all

1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl wxDataViewCtrl::wxDataViewCtrl(void)" (__imp_??0wxDataViewCtrl@@QEAA@XZ) referenced in function "public: __cdecl MyFrame::MyFrame(class wxString const &)" (??0MyFrame@@QEAA@AEBVwxString@@@Z)

1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl wxDataViewCtrl::~wxDataViewCtrl(void)" (__imp_??1wxDataViewCtrl@@UEAA@XZ) referenced in function "public: virtual void * __cdecl wxDataViewCtrl::`scalar deleting destructor'(unsigned int)" (??_GwxDataViewCtrl@@UEAAPEAXI@Z)

1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl wxDataViewCtrl::AllowMultiColumnSort(bool)" (?AllowMultiColumnSort@wxDataViewCtrl@@UEAA_N_N@Z)

1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl wxDataViewCtrl::AppendColumn(class wxDataViewColumn *)" (?AppendColumn@wxDataViewCtrl@@UEAA_NPEAVwxDataViewColumn@@@Z)

1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl wxDataViewCtrl::AssociateModel(class wxDataViewModel *)" (?AssociateModel@wxDataViewCtrl@@UEAA_NPEAVwxDataViewModel@@@Z)

1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl wxDataViewCtrl::CanScroll(int)const " (?CanScroll@wxDataViewCtrl@@UEBA_NH@Z)
.....................
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl implementation failure

Post by doublemax »

I'm probably missing a .dll that isn't provided with the archive file?
I don't know, but that's unlikely.

I've never used the precompiled binaries, so i can't tell what's wrong. Probably something in your project settings. Can you build the "dataview" sample?

As building the wx libraries yourself if almost trivial with VS, maybe give that a try.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewCtrl implementation failure

Post by ONEEYEMAN »

Hi,
Also, when you have a problem like this its always better to have a debug build.
Then if something goes wrong you might be able to either step inside wx code or get a good crash backtrace.

Thank you.
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: wxDataViewCtrl implementation failure

Post by papillon68 »

Ok so thanks to all responses I managed to get a step further and understand at least the issues. Latest problem about the unresolved external symbol was simply the wxmsw31u_adv.lib dependency missing.
The problem of the application shutting down silently, both in debug and release mode, is produced when adding a wxDataViewCtrl, without a valid wxDataViewIndexListModel, to a wxSizer.
In that case the UI simply doesn't show up and after a couple of seconds the application closes gracefully.
In my naivety, I thought that even without a data model attached the wxDataViewCtrl would at least show up empty. I discovered this studying a bit the dataview sample as suggested earlier.
So now I will dig more to create the data list model and finally bind it to the wxDataViewCtrl: I see there are no minimal examples around, like adding just a simple item for the sake of testing, but at least there is the dataview sample to help :)
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewCtrl implementation failure

Post by ONEEYEMAN »

Hi,
wxDataViewCtrl is a huge control with the big public API.
The dataview sample was made to demonstrate and test all of its abilities. And unfortunately for this control the sample is big.

I think (I may be wrong though) that the reason behind creating the wxDVC was to implement wxListCtrl/wxTreeCtrl as native controls on *nix/OSX. But instead it became its own control.

Now of course there are also wxList{Ctrl,View} and wxTreeCtrl, which are native on Windows, but generic on *nix/OSX. They have simpler public API. So you need to ask yourself whether you need the overhead of wxDVC or 1 of those 2 will suffice.

If you have a problem with the control (as with anything in the wx world), the very first step is to reproduce the problem in the sample.

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDataViewCtrl implementation failure

Post by PB »

I could not reproduce the issue. I replaced contents of the dataview.cpp in dataview sample (and removed unused files from the project) with

Code: Select all

#include <wx/wx.h>
#include <wx/dataview.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 400))
    {                                       
        wxButton* myButton = new wxButton(this, wxID_ANY, "New");
        wxDataViewCtrl* listCtrl= new wxDataViewCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
            wxDV_NO_HEADER | wxDV_VARIABLE_LINE_HEIGHT); 
        
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
        mainSizer->Add(myButton, wxSizerFlags().Expand().Proportion(0).Border(wxALL, 10));
        mainSizer->Add(listCtrl, wxSizerFlags().Expand().Proportion(1).Border(wxALL, 10)); 
        SetSizer(mainSizer);        
    }	
};

class MyApp : public wxApp
{
public:	
	bool OnInit()
	{
        (new MyFrame)->Show();
        return true;
	}
}; wxIMPLEMENT_APP(MyApp);
and the app runs as expected.

wxWidgets 3.1.1 32-bit static debug built by myself, MSVC 2017 Express, Win10
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: wxDataViewCtrl implementation failure

Post by papillon68 »

Found what was wrong, ashamed to say it was a wrong setting in the Visual Studio C/C++ Code Generation settings, where I set the /MTd flag rather than the /MD flag.
So basically it was mixing non-debug libraries linking with debug ones. Result: application would start and silently shut down after few seconds with no crashes or errors, and only when using specific controls like wxComboBox or wxDataViewCtrl.
Hope it can help other newbies if they fall into this issue.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewCtrl implementation failure

Post by ONEEYEMAN »

Hi,
In order to start with the wxWidgets it is suggested you start with the mionimal sample folder or any other sample that best suit you needs.

Thank you.
Post Reply