SQL relational table update



  • I'm learning to use qt and sql. I tested a very similar program with QSqlTableModel and I can edit the data directly from the table view in the dialog. When I use QSqlRelationalTableView, which inherits QSqlTableModel the changes on the table are not transfer to the database. Is there a command to give to update the database?
    I'm just playing with this now but eventually I will be building an application where I can add and modify certain data from the application.

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);

    db = QSqlDatabase::addDatabase("QMYSQL");
    
    db.setHostName("192.168.1.14");
    db.setDatabaseName("Radio");
    db.setUserName("aaaaa");
    db.setPassword("bbbbb");
    
    if(db.open()==false)
    {
        QMessageBox::warning(this,"Error","Coudl not Open Database");
    }
    
    model = new QSqlRelationalTableModel(this);
    model->setTable("Brand");
    model->setRelation(7,QSqlRelation("Poster","idPoster","posterName"));
    model->select();
    ui->tableView->setModel(model);
    

    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.