PDA

View Full Version : QList.replace continuous error



Jonathan Maen
23rd January 2012, 07:14
Hello,

I've problems with my application, see, I've a MainWindow which contains a QListWidget and a variable QList<MyStruct> as public. There's a PushButton which opens a new Window, which I can add items to my QList and show them into my QListWidget, but the problem is that I've another PushButton, to edit an existing item, I seem to be allowed to parse the item (struct) successfully to the second Window, but trying to save that item back (replace) crashes my app with a debugger error that says "The inferior stopped because it received a signal from the Operating System".

This is the code I'm using;




//Edit Conversation
void MainWindow::on_pushButton_4_clicked()
{

QModelIndexList indexes = ui->listTalk->selectionModel()->selectedIndexes();
ConversationWindow *dlg = new ConversationWindow(this);
dlg->isEdit = true;

dlg->editConversation((quint8)indexes.at(0).row(), TalkList.at(indexes.at(0).row()));

if (indexes.count() > 0)
dlg->show();
}




// Add or Edit existing conversation
void ConversationWindow::on_pushButton_2_clicked()
{
ConversationItem item;

if (!isEdit)
{
item.Key1_t = ui->lineEdit->text();
item.Key2_t = ui->lineEdit_2->text();
item.Key3_t = ui->lineEdit_3->text();
item.getState = ui->checkBox->checkState();
item.setState = ui->checkBox_2->checkState();
item.getStateValue = ui->spinBox->value();
item.setStateValue = ui->spinBox_2->value();
item.JustAnswer = ui->checkBox_3->checkState();
item.Answer_t = ui->lineEdit_4->text();
item.isScript = ui->checkBox_5->checkState();
item.Script_t << ui->textEdit->toPlainText();

list->append(item);

close();

window->DrawTalk();
} else {
item.Key1_t = ui->lineEdit->text();
item.Key2_t = ui->lineEdit_2->text();
item.Key3_t = ui->lineEdit_3->text();
item.getState = ui->checkBox->checkState();
item.setState = ui->checkBox_2->checkState();
item.getStateValue = ui->spinBox->value();
item.setStateValue = ui->spinBox_2->value();
item.JustAnswer = ui->checkBox_3->checkState();
item.Answer_t = ui->lineEdit_4->text();
item.isScript = ui->checkBox_5->checkState();
item.Script_t << ui->textEdit->toPlainText();

// I've tried with replace but same error appears.
list->removeAt(editIndex);
list->insert(editIndex, item);

isEdit = false;
}
}


I'm parsing the item index correctly checked with debug.
Please help me :()

ChrisW67
23rd January 2012, 07:32
Run the program in a debugger. When it crashes inspect the backtrace and the value of variables in use at the time.

What set "list" in ConversationWindow and what is its value? I am betting it is null or invalid.

Jonathan Maen
23rd January 2012, 07:44
Run the program in a debugger. When it crashes inspect the backtrace and the value of variables in use at the time.

What set "list" in ConversationWindow and what is its value? I am betting it is null or invalid.

Thank you, the error was that I forgot to parse my list from MainWindow to EditWindow pointer variable.

I'm still learning second day with Qt & C++ lol.