I am a Cainiao and am working on a simple record recording system. this is the next interface! IMG (img.ask.csdn.netupload201509201442729281_633123.png )! IMG (img.ask.csdn.netupload201509201442729338_641477.png. The following is my code: #... mysqlqtqsqlquerymodel database
I am a Cainiao working on a simple record recording system,
This is the interface after entering
I want to select a table and click "modify student information". then, I can synchronously refresh the MySQL database after the table is modified and confirmed, and the data in the table is also updated.
The following is my code:
# Include "record. h"
# Include "ui_record.h"
# Include "land. h"
# Include "login. h"
# Include
# Include
# Include
# Include "mysql_object.h"
# Include
# Include
# Include
# Include
# Include
QString str = "";
Record: record (QWidget * parent ):
QDialog (parent ),
Ui (new Ui: record)
{
Ui-> setupUi (this );
Db = MySql_Object: GetInstance ();
QTextCodec: setCodecForTr (QTextCodec: codecForLocale ());
Model = new QSqlQueryModel (this); ui-> tableView-> horizontalHeader ()-> setResizeMode (QHeaderView: Stretch); QString SQL = QString ("select name, age, sex from classmate where id = % 1 "). arg (land: Id); model-> setQuery (SQL); model-> setHeaderData (0, Qt: Horizontal, tr ("classmate name ")); model-> setHeaderData (1, Qt: Horizontal, tr ("age"); model-> setHeaderData (2, Qt: Horizontal, tr ("gender ")); ui-> tableView-> setModel (model );
}
Record ::~ Record ()
{
Delete ui;
}
Void record: on_pushButton_add_2_clicked ()
{
Land * Land = new land ();
Land-> show ();
This-> hide ();
Return;
}
Void record: on_pushButton_change_clicked ()
{
/* QItemSelectionModelSelectionModel = ui-> tableView-> selectionModel ();
QModelIndexList selected = selectionModel-> selectedRows ();
QList rows;
Foreach (const QModelIndex & index, selected)
{
Rows. append (index. row ());
}
Str = model-> data (model-> index (rows [0], 10). toString ();
// Model-> setItemData (str );
Ui-> tableView_2-> setModel (model );
// Int row = ui-> tableView-> currentIndex (). row ();
// Model-> removeRow (row );/
// Model->
}