c++ - wxDataViewListCtrl 单击项目操作未执行
问题描述
当一个项目被点击时,我有一个wxDataViewListCtrl
绑定的,
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this, BCID_SampleListView);
相关的功能是,
void Browser::OnClickSampleView(wxDataViewEvent& event)
{
std::cout << "\n Click Sample View \n";
std::string selection = SampleListView->GetTextValue(SampleListView->GetSelectedRow(), 1).ToStdString();
std::cout << selection << "\n";
}
但是当我点击一个项目时什么都没有发生,没有任何东西打印到控制台没有错误。我究竟做错了什么?
我已经尝试在没有 ID 的情况下绑定它SampleListView->Bind()
,也没有运气。
我在 wxWidgets 论坛上问了这个问题,但是没有人能够弄清楚问题所在,有人让我试试这个,
SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) {
wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
这有效,它可以很好地打印到控制台,
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
链接到该项目的行,其中有Bind()
- https://gitlab.com/apoorv569/cpp-projects/-/blob/master/wxWidgets/SampleBrowser/src/Browser.cpp#L142
编辑:
在对该应用程序进行了一些试验后,我注意到在我向 wxDataViewListCtrl 添加单个条目后,所有按钮和我捕获事件的所有内容都停止工作,因此我进一步调查了我用来添加数据的函数对于 wxDataViewListCtrl,我也将所有数据插入到 Sqlite3 数据库中,我注意到如果我注释该行,将数据插入到 Sqlite3 数据库中,一切正常。
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;
}
正如你在上面看到的,我已经注释掉了向 Sqlite3 数据库插入数据的行,db.InsertSample()
看起来像这样
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();
}
}
我不能说数据库是否有问题或目前是什么问题,我仍在寻找,如果您发现任何问题,请告诉我。
链接到Database.cpp
文件 - https://gitlab.com/apoorv569/cpp-projects/-/blob/master/wxWidgets/SampleBrowser/src/Database.cpp
解决方案
推荐阅读
- powershell - ForEach-Object循环中的Powershell“Move-Item:该进程无法访问该文件,因为它正被另一个进程使用”
- excel - Python 3.9,Pandas - 如何在现有的 excel 中附加数据框
- amazon-web-services - 在 AWS Cloudformation 控制台中获取完整的事件文本
- java - 尝试根据用户输入调用方法,然后在 IF 语句内部调用进一步的输入选项
- firebase - Firestore/Android Studio:空对象参考 - 获取云值到类并在主活动中使用它?
- php - 检查用户是否已存在的函数
- sql-server - 根据 SQL 中的其他内容在插入时更新字段
- docker - Docker-compose 在 IPv6 上公开端口
- python - discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:__init__()缺少1个必需的位置参数:'source'
- go - 如何正确测试 Gin-gonic 控制器?