2013-10-09 28 views
0

在我的項目中,我有一個listWidget。當用戶點擊列表中的一個項目時,它會加載:Qt當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); 
    } 
} 

大部分情況是字符串操作。 (你不需要學習這個語法或任何東西)

我的問題是,當用戶快速點擊另一個列表項(在當前過程完成之前)程序崩潰。有什麼辦法可以快速點擊(多個進程一次)或者可能是一個替代解決方案?

感謝您的時間:)

+3

這個問題是關於一個錯字。除提問者之外,問題和答案都不會對任何人有任何幫助。請參閱[這篇meta文章](http://meta.stackexchange.com/questions/167342/close-all-the-typo-questions)瞭解一些基本原理。 –

回答

1

我希望你在GUI線程中執行所有這些代碼。如果是這樣,那麼就沒有問題 - 如果你的代碼是正確的(不是)。在你的問題中沒有提到你提到的「過程」。點擊由一個插槽處理,並從列表中的事件處理程序調用它們。這是而不是應該會崩潰,並且點擊將以序列化方式處理 - 一個接一個。

這裏的錯誤:爲什麼你重置分配的UI指針元素的值爲零?

ui->damageIdIn = 0; 

這是無稽之談。也許你的意思是ui->damageIdIn->setValue(0)ui->damageIdIn->hide()。然後你繼續使用這個零值在

ui->damageIdIn->setValue(temp_int); 

它崩潰。

您的代碼中的其他地方也可能存在錯誤。

+0

謝謝:)我覺得自己像一個傻瓜XD – mrg95