Results 1 to 3 of 3

Thread: dataChanged fired unexpectedly

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    46
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default dataChanged fired unexpectedly

    Good afternoon -

    Had something happen earlier that I can't explain and I was wondering if someone could a) help explain it, and b) help get around it.

    I'm currently capturing a dataChanged() signal on a particular QSqlTablemodel in order to activate a "Save" button. Upon hitting a certain "edit" pushbutton, I'm presented with a dialog allowing me to modify a single field from that model. I hit cancel and the dataChanged() signal is *not* fired, as expected. I again hit "edit" and immediately the signal is fired at the same time the dialog is generated. I didn't expect that to happen and I can't figure out how to prevent that from happening because there's no reason to activate the Save button if I haven't actually changed anything in the model. Here is my setup

    Qt Code:
    1. //****************************************************************************
    2. void MainWindow::RigSetup()
    3. {
    4. //*****************
    5. //* Rig Data... *
    6. //*****************
    7. rigmodel = new QSqlTableModel(this, sqldb->db);
    8.  
    9. rigmodel->setTable ("rig");
    10. rigmodel->sort (1, Qt::AscendingOrder);
    11. rigmodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
    12.  
    13. connect(rigmodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
    14. this, SLOT(set_save_flag ()));
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //****************************************************************************
    2. void MainWindow::on_EditRigAdminPB_clicked()
    3. {
    4. bool ok;
    5. int current_index;
    6.  
    7. QString oldrig_name;
    8. QString newrig_name;
    9. QString message;
    10. QSqlRecord rig_record;
    11.  
    12. current_index = ui->RigAdminNameCB->currentIndex ();
    13. rig_record = rigmodel->record (current_index);
    14. oldrig_name = rig_record.value("rig_name").toString();
    15.  
    16. //***********************************
    17. //* Go get a name for this rig... *
    18. //***********************************
    19. ok = false;
    20. message = "Enter a New Name for this Rig: " + oldrig_name;
    21. newrig_name = QInputDialog::getText (this, "Rig Name Change",
    22. message, QLineEdit::Normal, QString(), &ok);
    23.  
    24. if (ok && !newrig_name.isEmpty ())
    25. {
    26. if (!rig_mgr)
    27. rig_mgr = new RigManager;
    28.  
    29. if (rig_mgr->dup_rig_name_check (rigmodel, newrig_name))
    30. {
    31. QMessageBox::warning (this, "Rig Name exists",
    32. "A Rig data set of this name "
    33. "already exists. Please re-enter.");
    34. }
    35. else
    36. {
    37. //* Copy the data into the model... *
    38. rig_mgr->edit_rig(rigmodel, user, newrig_name, current_index)
    39.  
    40. }
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //****************************************************************************
    2. void MainWindow::set_save_flag ()
    3. {
    4. ui->actionSave_All->setEnabled(true);
    5. }
    To copy to clipboard, switch view to plain text mode 

    I did some checking and it's the "rig name" field that's dirty. I'd really not have to subclass anything to get around this...


    Kodi
    Last edited by mtnbiker66; 25th February 2013 at 18:58.

Similar Threads

  1. emitDataChanged and dataChanged signal
    By fruzzo in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2012, 15:47
  2. QSqlTableModel & datachanged()
    By noValue in forum Newbie
    Replies: 5
    Last Post: 26th November 2010, 00:26
  3. Clarification about dataChanged
    By airbites in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 16:02
  4. QAbstractTreeModel & dataChanged()
    By tntcoda in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 00:12
  5. dataChanged does not re-sort the view
    By alex9099 in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2008, 20:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.