Qt 当列表小部件项被单击两次时崩溃
Qt Crash when listWidget item is clicked twice
在我的项目中,我有一个listWidget。当用户单击列表中的项目时,它将加载以下内容:
void BlockSelect::on_blockList_clicked(const QModelIndex &index)
{
QString blockListName;
QString temp_hex;
QString temp_hex2;
int temp_int;
QListWidgetItem *newitem = ui->blockList->currentItem();
blockListName = newitem->text();
temp_hex = blockListName.mid(0, blockListName.indexOf(" "));
if(temp_hex.indexOf(":") == -1)
{
temp_int = temp_hex.toInt();
ui->blockIdIn->setValue(temp_int);
ui->damageIdIn = 0;
}
else
{
temp_hex2 = temp_hex.mid(temp_hex.indexOf(":")+1, temp_hex.length()-(temp_hex.indexOf(":")+1));
temp_hex = temp_hex.mid(0, temp_hex.indexOf(":"));
temp_int = temp_hex.toInt();
ui->blockIdIn->setValue(temp_int);
temp_int = temp_hex2.toInt();
ui->damageIdIn->setValue(temp_int);
}
}
其中大部分只是字符串操作。(你不需要研究这个语法或任何东西)
我的问题是,当用户快速单击另一个列表项(在当前过程完成之前)时,程序崩溃。有没有办法允许快速点击(一次多个进程)或替代解决方案?
感谢您抽出宝贵时间:)
我希望
您在 GUI 线程中执行所有这些代码。如果是这样,那么就不会有问题 - 如果你的代码是正确的(它不是)。没有您在问题中提到的"过程"之类的东西。单击由槽处理,并从列表中的事件处理程序调用它们。这不应该崩溃,点击将以序列化的方式处理 - 一个接一个。
这是错误:为什么要将分配的 UI 指针元素的值重置为零?
ui->damageIdIn = 0;
这是无稽之谈。也许你的意思是ui->damageIdIn->setValue(0)
或ui->damageIdIn->hide()
.然后,您继续在
ui->damageIdIn->setValue(temp_int);
它崩溃了。
代码中的其他地方也可能有 bug。
相关文章:
- g++的分段错误(在NaN上使用to_string两次时)
- 蛇在C++不会连续转两次
- 检查一个数组是否包含在另一个数组中,以相反的顺序,至少两次
- 从具有按值捕获的 lambda 移动构造 std::函数时,移动构造函数调用两次
- 我应该如何去缓解两次出现的cin?
- Realloc 两次无法在 Visual Studio 上运行
- 使用 getline(cin, var) 两次在进行字符串比较时会产生错误 (==)
- 为什么映射插入和 map.find() 的单次迭代比插入和 map.find() 的两次单独迭代慢得多
- C++析构函数调用两次,堆栈分配的复合对象
- 为什么参数在构造 std::thread 时移动两次
- Qt插槽调用了两次
- 做 std::用相同的unique_ptr移动两次
- C++两次定义相同的函数会导致错误
- 为什么具有静态存储持续时间的同一内联变量在包含在 VS2017 编译的两个翻译单元中时会构造和销毁两次
- C 如何使功能崩溃两次(32位机器)
- 静态 c++ 对象中的 JNI 环境指针并调用连续两次使用字符串参数的 Java 函数会使 JVM 崩溃
- Qt 当列表小部件项被单击两次时崩溃
- 为什么我的程序不崩溃,如果析构函数被调用两次
- 调用两次的析构函数会导致崩溃
- 为什么删除指针两次会导致崩溃