wxDataViewListCtrl on click item action not executing.

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.
apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Thu Jan 14, 2021 10:47 am

ONEEYEMAN wrote:
Thu Jan 14, 2021 1:32 am
Hi,
Yes, something is very fishy happenning there.

Try to create the control with "this" (Browser) pointer as a parent.

If that doesn't help - strip down you code until it starts working.

And do use the:

Code: Select all

wxDVC->Bind()
code and without the ID of the control.

Thank you.
I created the control with "this" pointer as parent, (using both wx 3.1.4 and 3.0.5)

Code: Select all

    SampleListView = new wxDataViewListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES);
and binding as,

Code: Select all

    SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
This obviously messed up the position of the control, but nothing works still.

User avatar
doublemax
Moderator
Moderator
Posts: 15688
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl on click item action not executing.

Post by doublemax » Thu Jan 14, 2021 11:40 am

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, SampleListView](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
What happens with this code?
Use the source, Luke!

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Thu Jan 14, 2021 12:12 pm

doublemax wrote:
Thu Jan 14, 2021 11:40 am

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, SampleListView](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
What happens with this code?
I get an error while compiling,

Code: Select all

FAILED: SampleBrowser.p/src_Browser.cpp.o
g++ -ISampleBrowser.p -I. -I.. -I/usr/lib/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -I/usr/include/taglib -fdiagnostics-color=always -pipe -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++14 -g -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -MD -MQ SampleBrowser.p/src_Browser.cpp.o -MF SampleBrowser.p/src_Browser.cpp.o.d -o SampleBrowser.p/src_Browser.cpp.o -c ../src/Browser.cpp
../src/Browser.cpp: In constructor ‘Browser::Browser(wxWindow*)’:
../src/Browser.cpp:165:67: error: capture of non-variable ‘Browser::SampleListView’
  165 |     SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, SampleListView](wxDataViewEvent &e) {
      |                                                                   ^~~~~~~~~~~~~~
In file included from ../src/Browser.cpp:1:
../src/Browser.hpp:72:29: note: ‘wxDataViewListCtrl* Browser::SampleListView’ declared here
   72 |         wxDataViewListCtrl* SampleListView;
      |                             ^~~~~~~~~~~~~~

User avatar
doublemax
Moderator
Moderator
Posts: 15688
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl on click item action not executing.

Post by doublemax » Thu Jan 14, 2021 12:22 pm

Forgot SampleListView is not a local variable in your case. Try this:

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
Use the source, Luke!

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Thu Jan 14, 2021 12:38 pm

doublemax wrote:
Thu Jan 14, 2021 12:22 pm
Forgot SampleListView is not a local variable in your case. Try this:

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
Okay this is printing to the console,

Code: Select all

18:07:06: Debug: dataviewevent row 0
18:07:07: Debug: dataviewevent row 1
18:07:09: Debug: dataviewevent row 2
18:07:10: Debug: dataviewevent row 3

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Sun Jan 17, 2021 4:01 pm

doublemax wrote:
Thu Jan 14, 2021 12:22 pm
Forgot SampleListView is not a local variable in your case. Try this:

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
Okay, I tried making another sample test project to see if it prints when I click on wxDataViewListCtrl, and it does, so there is something in my code that is messing it up.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 19, 2021 1:49 pm

doublemax wrote:
Thu Jan 14, 2021 12:22 pm
Forgot SampleListView is not a local variable in your case. Try this:

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) { 
    wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
I think I might have found the bug in my code, today while experimenting again with the application, I noticed that all buttons and everything that I'm catching event for stops working after I add a single entry to the wxDataViewListCtrl, so I investigated further and in the function which I'm using to add data to wxDataViewListCtrl, I'm inserting all that data to Sqlite3 database also, I noticed that If I comment that line, that inserts data to Sqlite3 database, everything works fine.

Code: Select all

void Browser::OnClickDirCtrl(wxCommandEvent& event)
{
    TagLib::FileRef File (DirCtrl->GetFilePath());
    TagLib::String Artist = File.tag()->artist();
    TagLib::String Album = File.tag()->album();
    TagLib::String Genre = File.tag()->genre();
    TagLib::String Title = File.tag()->title();
    TagLib::String Comment = File.tag()->comment();
    int Bitrate = File.audioProperties()->bitrate();
    int Channels = File.audioProperties()->channels();
    int Length = File.audioProperties()->lengthInMilliseconds();
    int LengthSec = File.audioProperties()->lengthInSeconds();
    int SampleRate = File.audioProperties()->sampleRate();
    
    std::string Path = DirCtrl->GetFilePath().ToStdString();
    
    char c = '/';
    std::string Filename = DirCtrl->GetFilePath().AfterLast(c).ToStdString();

    wxVector<wxVariant> Data;
    Data.clear();
    Data.push_back(false);
    Data.push_back(Filename);
    Data.push_back(TagLibTowx(Artist));
    Data.push_back(wxString::Format("%d",Channels));
    Data.push_back(wxString::Format("%d",LengthSec));
    Data.push_back(wxString::Format("%d",SampleRate));
    Data.push_back(wxString::Format("%d",Bitrate));
    Data.push_back(TagLibTowx(Comment));

    SampleListView->AppendItem(Data);

    // db.InsertSample(0, Filename, Artist.to8Bit(), Channels, Length,
                    // SampleRate, Bitrate, Comment.to8Bit(), Path);

    wxString sample = db.GetSamplePathByFilename(std::string(Filename));
    std::cout << "Sample: " << sample << std::endl;
}
As you can see above I have commented out the line which inserts data to Sqlite3 database which is `db.InsertSample()` which looks like this

Code: Select all

void Database::InsertSample(int Favorite, std::string Filename,
                            std::string SamplePack, int Channels, int Length,
                            int SampleRate, int Bitrate, std::string Comment,
                            std::string Path)
{
    try
    {
        rc = sqlite3_open("Samples.db", &DB);

        sql = "INSERT INTO SAMPLES (FAVORITE, FILENAME, SAMPLEPACK, CHANNELS, \
                                    LENGTH, SAMPLERATE, BITRATE, BITSPERSAMPLE, PATH) \
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";

        rc = sqlite3_prepare_v2(DB, sql.c_str(), sql.size(), &stmt, NULL);   // create the prepared statement
        rc = sqlite3_bind_int(stmt, 1, Favorite);
        rc = sqlite3_bind_text(stmt, 2, Filename.c_str(), Filename.size(), SQLITE_STATIC);
        rc = sqlite3_bind_text(stmt, 3, SamplePack.c_str(), SamplePack.size(), SQLITE_STATIC);
        rc = sqlite3_bind_int(stmt, 4, Channels);
        rc = sqlite3_bind_int(stmt, 5, Length);
        rc = sqlite3_bind_int(stmt, 6, SampleRate);
        rc = sqlite3_bind_int(stmt, 7, Bitrate);
        rc = sqlite3_bind_text(stmt, 8, Comment.c_str(), Comment.size(), SQLITE_STATIC);
        rc = sqlite3_bind_text(stmt, 9, Path.c_str(), Path.size(), SQLITE_STATIC);

        if (sqlite3_step(stmt) != SQLITE_DONE)
        {
            std::cout << "Not inserted data." << "\n";
        }
        
        rc = sqlite3_finalize(stmt);

        if (rc != SQLITE_OK)
        {
            std::cerr << "Error! Cannot insert data into table." << std::endl;
            sqlite3_free(ErrorMessage);
        }
        else if (rc == SQLITE_BUSY)
        {
            std::cout << "BUSY" << std::endl;
        }
        else if (rc == SQLITE_DONE)
        {
            std::cout << "DONE" << std::endl;
        }
        else if (rc == SQLITE_ERROR)
        {
            std::cout << "ERROR" << std::endl;
        }
        else if (rc == SQLITE_MISUSE)
        {
            std::cout << "MISUSE" << std::endl;
        }
        else
        {
            std::cout << "Data inserted successfully." << ErrorMessage << std::endl;
        }

        sqlite3_close(DB);
    }
    catch (const std::exception &exception)
    {
        std::cerr << exception.what();
    }
}
I can't say if something is wrong with the database or what at this point, I'm still looking, please if you see anything wrong let me know.

Link to the Database.cpp file - https://gitlab.com/apoorv569/cpp-projec ... se.cpp#L45

User avatar
doublemax
Moderator
Moderator
Posts: 15688
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl on click item action not executing.

Post by doublemax » Tue Jan 19, 2021 2:52 pm

I can't spot anything obvious. Are you running a debug build? Does the sqlite call return an error? Is the exception thrown?
Use the source, Luke!

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 19, 2021 3:55 pm

doublemax wrote:
Tue Jan 19, 2021 2:52 pm
I can't spot anything obvious. Are you running a debug build? Does the sqlite call return an error? Is the exception thrown?
I'm using the meson build system, as recommended by a friend of mine, but I don't know how to specify a debug or release build. But I think the one I'm running is a debug.

This is my `meson.build` file,

Code: Select all

project('SampleBrowser', 'cpp',
  version : '0.1',
  default_options : ['warning_level=1',
                     'cpp_std=c++14'])

src = [

  'src/app.cpp',
  'src/MainFrame.cpp',
  'src/Browser.cpp',
  'src/Settings.cpp',
  'src/Database.cpp',

  ]

wx = dependency('wxwidgets', modules : ['media', 'std'])
taglib = dependency('taglib')
sqlite3 = dependency('sqlite3')

exec = executable('SampleBrowser', src,
  dependencies : [wx, taglib, sqlite3],
  install : true)

test('basic', exec)
Sqlite does not throw any error, the database is created successfully and all the data is added fine to the database, I have confirmed this by using sqlitebrowser a GUI to view sqlite databases. But as soon as I add one item to the wxDVC all output to console stops, and all buttons and other controls stop receiving events.
Last edited by apoorv569 on Tue Jan 19, 2021 3:58 pm, edited 1 time in total.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4870
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewListCtrl on click item action not executing.

Post by ONEEYEMAN » Tue Jan 19, 2021 4:01 pm

Hi,
This shouldn't happen.
Can you try to add this line to a minimal sample and see if the menu becomes responsive?

Thank you.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 19, 2021 4:18 pm

ONEEYEMAN wrote:
Tue Jan 19, 2021 4:01 pm
Hi,
This shouldn't happen.
Can you try to add this line to a minimal sample and see if the menu becomes responsive?

Thank you.
No, I mean app keeps working, only output to console stops, that is all the print statements won't print to console, and other buttons won't work as in don't do anything, because they no longer catch any event, but I can click them just fine.

See the first time I run the app with sqlite insert data function commented out, then later I un-comment that and recompile and after adding first sample all console output stops, and no button works.
Image

I have already tried making a minimal project that only has wxDVC, and it works fine, even in this project it works, if I comment out the sqlite insert data function.

Something about sqlite is messing the app or something.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4870
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewListCtrl on click item action not executing.

Post by ONEEYEMAN » Tue Jan 19, 2021 5:55 pm

Hi,
But in that minimal code - if you use the SQLite function then the behavior is the same? Do you use wxSQLite or native SQLite calls?

What OS do you use? What wx version?

I am not using an insertion to SQLite DB - only SELECT but for me everything works just fine.
Thank you.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 19, 2021 8:27 pm

ONEEYEMAN wrote:
Tue Jan 19, 2021 5:55 pm
Hi,
But in that minimal code - if you use the SQLite function then the behavior is the same? Do you use wxSQLite or native SQLite calls?
I added sqlite code in the minimal example project, same thing is happening after adding the sqlite code. I'm using native Sqlite3.

I think the problem lies somewhere in the `InsertData()` because I have another function in my actual project called `GetPathByFilename()` which essentially gets a column data by inputting a filename, which runs fine, its just this `InsertData()`.
ONEEYEMAN wrote:
Tue Jan 19, 2021 5:55 pm
What OS do you use? What wx version?
I'm using Arch Linux, wx version is 3.0.5

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4870
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewListCtrl on click item action not executing.

Post by ONEEYEMAN » Tue Jan 19, 2021 8:34 pm

Hi,
This is really weird.
You are using the stock SQLite, right? And you perform insertions(s) in the thread?
And you don't do GUI access from a secondary thread?

Thank you.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 19, 2021 8:49 pm

ONEEYEMAN wrote:
Tue Jan 19, 2021 8:34 pm
Hi,
This is really weird.
You are using the stock SQLite, right? And you perform insertions(s) in the thread?
And you don't do GUI access from a secondary thread?

Thank you.
Yes I'm using stock SQLite, sorry I don't understand what you mean by thread. All the GUI part is in one file except a settings dialog. And all the SQLite database stuff is in another file called Database.hpp and Database.cpp, which I call the InsertData() from within the GUI file by creating a object of the Database class as db to insert the data in the database.

Here is the link to the minimal test project I made which is causing the same problem I have in the original project. The structure is not exactly the same as original project but the problem is. https://drive.google.com/file/d/1vzzlaw ... sp=sharing

You can run `meson build` then `meson compile -C build` then run the binary with `./build/wxDvcTest`.

Post Reply