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. Saving data before SubmitAll()
Forum Updated to NodeBB v4.3 + New Features

Saving data before SubmitAll()

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 234 Views 1 Watching
  • 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.
  • I Offline
    I Offline
    Incognito_style
    wrote on last edited by Incognito_style
    #1

    I am editing a database using qsqltablemodel using TableView, and when entering unsuitable values, an error is returned, and the entered data is not saved, and if the error occurs in one cell, the entire row must be re-entered. Tell me how this can be fixed without removing the save button and without changing the database editing strategy
    I tried to check the data before sending All(), but it doesn't help
    Code example:

    if(!correct_data)
    {
        QMessageBox::warning(this,"Error","Data is not correct");
    }
    else
    {
        model->submitAll();
    }
    

    If the data is incorrect, the program shows a Qmessagebox and deletes the data that has just been entered. How to fix it?
    The gif shows an error when entering an unsuitable value according to the database conditions. The program automatically returns to the last saved values, although I did not prescribe this

    [GIF with error]new.gif

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What is the rest of the logic when you click on that button ?
      How are you adding that row to your QTableView ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Incognito_style
        wrote on last edited by Incognito_style
        #3

        How are you adding that row to your QTableView ?

        void admin_interface::on_pushButton_add_clicked() 
        {
            model->insertRow(model->rowCount());
        }
        

        What is the rest of the logic when you click on that button?

        Before I tried to check the data in the tableView it looked like this

        void admin_interface::on_pushButton_refresh_clicked()
        {
            if(model->submitAll()) 
            {
            }
            else if (model->lastError().text()==" No Fields to update")
            {
                qDebug()<<model->lastError().text();
                QMessageBox::warning(this,"Error","");
            }
            else
            {
                qDebug()<<model->lastError().text();
                QString text = model->lastError().text();
                QStringList lines = text.split( '\n' );
                QMessageBox::warning(this,"Error",lines[0]);
            }
            model->setEditStrategy(QSqlTableModel::OnManualSubmit);
            row_count = model->rowCount();
        
        }
        
        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