Moezzie
15th December 2007, 12:55
I have this little program ive been working on for the last week or so and it almost finished but i just cant get the editing function to work.
I have a tree widget with a couple of items in it. When i select one and hit the edit-button a dialog pops up and asks the user to input two new values. When the ok-button is clicked these values are sent to an edit function which is supposed to edit the selected item.
It seems like a really easy job, but somehow it does not work. However it workes just fine in another function so i have no idea whats wrong.
void MainWindowImpl::button_edit_clicked()
{
// If an item is selected open the dialog
if(treeWidget->currentItem())
{
EditDialog *dialog = new EditDialog;
dialog->show();
}
// Edit the selected item
// This one workes fine. Its just a test though
if(treeWidget->currentItem())
{
item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
item->setText(1, "New Date");
treeWidget->insertTopLevelItem(0, item);
}
//check
qDebug() << "Edit clicked";
}
// the new values are passed to this funktion
void MainWindowImpl::edit_item(QString col0, QString col1)
{
// This one does not work, its the same as the same one as above but it produces an error
// When i try to put it inside of a similar if-statementas above, it returns false
// I guess it has something with the selection to do then
item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
item->setText(1, "New Date2");
treeWidget->insertTopLevelItem(0, item);
qDebug() << "Items Recived:" << col0 << col1;
}
This is the debug message i get:
Sending Items: "dsa" and "01.Jan 00"
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1224956224 (LWP 8040)]
0x0804f736 in QTreeWidgetItem::setText (this=0x0, column=1, atext=@0xbf9cadcc) at /usr/include/qt4/QtGui/qtreewidget.h:216
}
, alloc = 0
, size = 0
, data = 0x8058d92, clean = 0
, simpletext = 0
, righttoleft = 0
, asciiCache = 0
, capacity = 0
, reserved = 0
, array = {0
}
}, static shared_empty = {ref = {value = 1
}
, alloc = 0
, size = 0
, data = 0xb774d44e, clean = 0
, simpletext = 0
, righttoleft = 0
, asciiCache = 0
, capacity = 0
, reserved = 0
, array = {0
}
}, d = 0x82db060, static codecForCStrings = 0x0}
Thanks for your time!
I have a tree widget with a couple of items in it. When i select one and hit the edit-button a dialog pops up and asks the user to input two new values. When the ok-button is clicked these values are sent to an edit function which is supposed to edit the selected item.
It seems like a really easy job, but somehow it does not work. However it workes just fine in another function so i have no idea whats wrong.
void MainWindowImpl::button_edit_clicked()
{
// If an item is selected open the dialog
if(treeWidget->currentItem())
{
EditDialog *dialog = new EditDialog;
dialog->show();
}
// Edit the selected item
// This one workes fine. Its just a test though
if(treeWidget->currentItem())
{
item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
item->setText(1, "New Date");
treeWidget->insertTopLevelItem(0, item);
}
//check
qDebug() << "Edit clicked";
}
// the new values are passed to this funktion
void MainWindowImpl::edit_item(QString col0, QString col1)
{
// This one does not work, its the same as the same one as above but it produces an error
// When i try to put it inside of a similar if-statementas above, it returns false
// I guess it has something with the selection to do then
item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
item->setText(1, "New Date2");
treeWidget->insertTopLevelItem(0, item);
qDebug() << "Items Recived:" << col0 << col1;
}
This is the debug message i get:
Sending Items: "dsa" and "01.Jan 00"
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1224956224 (LWP 8040)]
0x0804f736 in QTreeWidgetItem::setText (this=0x0, column=1, atext=@0xbf9cadcc) at /usr/include/qt4/QtGui/qtreewidget.h:216
}
, alloc = 0
, size = 0
, data = 0x8058d92, clean = 0
, simpletext = 0
, righttoleft = 0
, asciiCache = 0
, capacity = 0
, reserved = 0
, array = {0
}
}, static shared_empty = {ref = {value = 1
}
, alloc = 0
, size = 0
, data = 0xb774d44e, clean = 0
, simpletext = 0
, righttoleft = 0
, asciiCache = 0
, capacity = 0
, reserved = 0
, array = {0
}
}, d = 0x82db060, static codecForCStrings = 0x0}
Thanks for your time!