Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SQL relational table update
Qt 6.11 is out! See what's new in the release blog

SQL relational table update

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 510 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dan3460D Offline
    Dan3460D Offline
    Dan3460
    wrote on last edited by
    #1

    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);
    

    }

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved