Can't update Grid Layout
-
If I add data in sqlite db, it will be added in grid layout, but if I delete data from db, it will be deleted in grid layout, it will not update, the deleted data will show in grid layout, if I close the program and then open it, it will update. How to programmatically update the grid layout in QT.
OS : Linux
DB : Sqlite -
@Ramkumar-Mohan said in Can't update Grid Layout:
How to programmatically update the grid layout in QT.
You did not post your code nor did you explain how you're deleting entries from grid layout! How should anybody help you?
If you want to show data from database why don't you use https://doc.qt.io/qt-6/qtableview.html instead? -
QSqlQuery query; query.prepare("SELECT name FROM test"); query.exec(); int count=0; while(query.next()) { QString s=query.value(0).toString(); array[count]=s; count++; //qDebug()<<s; } int count1=0; const QSize btnSize = QSize(150, 50); for (int i=0;i<15 ;i++ ) { for (int j=0;j<5 ;j++ ) { if(count1==count) break; else { QPushButton *button = new QPushButton(array[count1]); button->setFixedSize(btnSize); button->setObjectName(array[count1]); connect(button, &QPushButton::clicked, this,&MainWindow::cald); ui->gridLayout->addWidget(button,i,j); count1++; } } }
According to the above code some buttons are add their name in grid layout and functions are store in db and save in table named test, and if a data delete in db is not remove widget in grid layout. how to remove the deleted data widget.
Delete function :
QString Name = "name15"; QSqlQuery query; query.prepare("Delete from test where name='"+Name+"'"); if(query.exec()) { qDebug()<<"Data Deleted"; ui->gridlayout->update(); }
-
@Ramkumar-Mohan said in Can't update Grid Layout:
how to remove the deleted data widget
Using https://doc.qt.io/qt-6/qgridlayout.html#takeAt for example.
Or https://doc.qt.io/qt-6/qlayout.html#removeWidget