TableWidget text changed
I'm trying to make a programm where I can add dynamicaly new pads and set properties. The pad name should be showed in a ListView, and the Properties of every pad should be showed in a TableWidget.
In a new Dialog I can type in names and then they will added to the ListWidget. The Names are connected with random properties(only to test it). Every time I click on a name in the ListWidget, in the TableWidgets will be shown the properties of this name. Now my Problem: I would make, that when I change the name or a property in the TableWidget it should change the new property in the list where I save the data. I didn't find a function which send a signal, when a text in the TableWidget changes. If I get the name I can search the name in the list and change the property.
Is that the right way or should I save the name with properties in an sql database?
Here you see my implementation of creating a new pad:
void MainWindow::set_pad_name(QString value)
pad.name = value;
pad.height = QString::number(rand());
pad.width = QString::number(rand());;
pad.pos_x = QString::number(rand());;
pad.pos_y = QString::number(rand());;
I found this function:
void MainWindow::on_tableWidget_properties_itemChanged(QTableWidgetItem *item)
if(item != NULL)
QListWidgetItem *item = new QListWidgetItem;
item = listWidget_pads_name->currentItem();
but every time I would compile it, the program crash without an error.
I think you need to use MVC paradigm.
http://doc.qt.io/qt-4.8/model-view-programming.html Read this ! You need one data source for two views
You are using the same item variable everywhere. That might be the source of your crash. itemChanged(...) signal gives which item has been changed on tableWidget. From this you can text(...). This you can set anywhere you want.
- Why are you creating the QListWidgetItem object again
- Why you are naming every variable as item only.
- Check the return value of current item().. It may be null as as well.
If you can give us the sample of your program we can help you better.
Thank you for your reply.
Here you can find my code:
If you have some other improvements I would like to hear these :)