Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 两次单击listWidget项时Qt崩溃_C++_Qt_Process_Crash_Qlistwidget - Fatal编程技术网

C++ 两次单击listWidget项时Qt崩溃

C++ 两次单击listWidget项时Qt崩溃,c++,qt,process,crash,qlistwidget,C++,Qt,Process,Crash,Qlistwidget,在我的项目中,我有一个listWidget。当用户单击列表中的项目时,将加载以下内容: void BlockSelect::on_blockList_clicked(const QModelIndex &index) { QString blockListName; QString temp_hex; QString temp_hex2; int temp_int; QListWidgetItem *newitem = ui->blockL

在我的项目中,我有一个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->damageId=0;
这是胡说八道。也许你的意思是
ui->damageIdIn->setValue(0)
ui->damageIdIn->hide()。然后继续在中使用此零值

ui->damageIdIn->setValue(temp_int);
它崩溃了


您的代码中的其他地方可能也有bug。

谢谢:)我觉得自己像个傻瓜。这个问题是关于打字错误的。除了询问者之外,这个问题和答案都不会对任何人有任何帮助。请参阅以了解一些基本原理。