void MyplayerWidget::slot_open_pBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames(this,"获取音视频文件", "./", "*.jpg *.mp3 *.mp4 *.avi"); // m_MfileNameAndFilePath.clear(); for(int i = 0;i < fileNames.count();i++) { QStringList strSplitList = fileNames.at(i).split("/"); QString str; for(int j = 0;j < strSplitList.count();j++) { str = strSplitList.at(strSplitList.count()-1); } m_MfileNameAndFilePath.insert(str,fileNames.at(i)); QListWidgetItem *item = new QListWidgetItem(str); item->setSizeHint(ITEM_SIZE); ui->listWidget->insertItem(i,item); } }
时间: 2023-06-14 12:03:55 浏览: 40
这是一个 Qt 程序的槽函数,用于处理点击打开文件按钮的事件。该函数会弹出一个文件对话框,让用户选择一个或多个文件。选择的文件类型必须是 jpg、mp3、mp4 或 avi。选择的文件路径会被保存在 m_MfileNameAndFilePath 中,同时在列表控件中添加一个新的列表项,显示文件名。其中,ITEM_SIZE 是一个常量,表示列表项的大小。
相关问题
void MyplayerWidget::slot_open_pBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames(this,"获取音视频文件", "./", "*.jpg *.mp3 *.mp4 *.avi"); // m_MfileNameAndFilePath.clear(); for(int i = 0;i < fileNames.count();i++) { QStringList strSplitList = fileNames.at(i).split("/"); QString str; for(int j = 0;j < strSplitList.count();j++) { str = strSplitList.at(strSplitList.count()-1); } m_MfileNameAndFilePath.insert(str,fileNames.at(i)); QListWidgetItem *item = new QListWidgetItem(str); item->setSizeHint(ITEM_SIZE); ui->listWidget->insertItem(i,item); } }如何修改让代码变成根据鼠标选择删除
你可以修改代码如下:
```
void MyplayerWidget::slot_delete_selected_clicked()
{
QList<QListWidgetItem*> selectedItems = ui->listWidget->selectedItems();
for(int i = 0; i < selectedItems.count(); i++)
{
QListWidgetItem *selectedItem = selectedItems.at(i);
QString fileName = selectedItem->text();
m_MfileNameAndFilePath.remove(fileName);
delete selectedItem;
}
}
```
这里我们使用了 `QListWidget::selectedItems()` 方法获取当前列表中被选中的所有项,并使用 `QListWidgetItem::text()` 方法获取选中项的文本(即文件名),然后从 `m_MfileNameAndFilePath` 中移除该文件名,并使用 `delete` 关键字删除选中项。
纠正以下arduino代码的错误 #define InBtnPin 3 #define OutDPin 13 class Button { public: //成员函数 Button(int pbtn,int dpin):buttonpin(pbtn),diodepin(dpin)(); ~Button(void)() void Fun(int buttonpin,int diodepin); int buttonpin; int diodepin; }; void Bu
有几个错误需要纠正:
1. 在构造函数和析构函数的定义中,应该去掉额外的括号。
2. 在构造函数的定义中,应该使用成员初始化列表来初始化成员变量。
3. 在 Button 类的定义中,成员函数 Fun 的声明缺少返回类型。
4. 在 Button 类的定义中,构造函数和析构函数的声明与实现不一致。
下面是修改后的代码:
```
#define InBtnPin 3
#define OutDPin 13
class Button {
public:
// 成员函数
Button(int pbtn, int dpin) : buttonpin(pbtn), diodepin(dpin) {}
~Button() {}
void Fun();
int buttonpin;
int diodepin;
};
void Button::Fun() {
// do something
}
void setup() {
Button myButton(InBtnPin, OutDPin);
myButton.Fun();
}
void loop() {
// do something
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)