Results 1 to 4 of 4

Thread: Simple removeRows isn't working...

  1. #1
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Simple removeRows isn't working...

    I feel like I keep stumbling on hard things to solve with simple code. I have 2 models, one a child of another, and the user of my app can delete a parent record, and subsequent child records. The problem is -- my model->removeRow command comes back as TRUE but no rows are removed from the model or the database even though I've performed a submitAll(). I count the rows in the child model before and it comes back with a count of 2, and after the removeRows() it's still equal to 2.

    The models are defined such that selecting the parent filters the child model. And adding rows works fine.

    Anyone have a thought? Thanks! (oh, and the qDebug() commands are just temporary for better error handling after I get it working)

    Qt Code:
    1. void MainWindow::on_DeleleRegionPB_clicked()
    2. {
    3. int region_index;
    4.  
    5. region_index = regionmapper->currentIndex ();
    6. qDebug() << flowlinemodel->rowCount ();
    7.  
    8. if (!flowlinemodel->removeRows (0, flowlinemodel->rowCount ()))
    9. qDebug() << "Not able to delete flowline rows";
    10. else
    11. qDebug() << "woo-Who!";
    12.  
    13.  
    14. // for (int i = 0; i < flowlinemodel->rowCount (); i++)
    15. // {
    16. // if (!flowlinemodel->removeRow (i))
    17. // qDebug() << "issues";
    18. // }
    19.  
    20. flowlinemodel->submitAll ();
    21. qDebug() << flowlinemodel->rowCount ();
    22.  
    23. if (!regionmodel->removeRow (region_index))
    24. qDebug() << "Not able to remove Region row";
    25.  
    26. if (region_index > 0)
    27. regionmapper->setCurrentIndex (region_index - 1);
    28. else
    29. regionmapper->setCurrentIndex (region_index);
    30.  
    31. refresh_RegionView ();
    32. set_Next_Previous_buttons();
    33. }
    To copy to clipboard, switch view to plain text mode 


    scott

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Simple removeRows isn't working...

    Please provide more info on the models.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Simple removeRows isn't working...

    Are there integrity constraints in the underlying database that might be violated by removing these rows?

  4. #4
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Simple removeRows isn't working...

    Thanks for reply -- I've completely redesigned this since then (thanks to my father-in-law's brilliant communications skills of saying one thing and meaning another), so this thread should be removed...

    Turns out, no, there weren't any constraints...I had had them on, but took them off thinking they were the problem...As part of my learning curve with cute, I've come to realize that using the model/view classes can sometimes cause unexpected results so I've gone straight to SQL a few times so that I know exactly how the code is behaving...Coming from a day job of Oracle I feel a lot more comfortable depending on the order of delete/insert/update at that level since I have no easy way of peeking at how the models (and in some cases the mapping) behave...

    thanks for the reply, though!


    scott

Similar Threads

  1. Simple Widget ToolTips Not Working
    By powerofpi in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2011, 04:19
  2. removeRows in a QTreeView
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2009, 00:37
  3. What is wrong with this simple example ?
    By igor in forum Qt Programming
    Replies: 10
    Last Post: 16th January 2007, 11:26
  4. can't get a simple dialog working
    By pthomas in forum Newbie
    Replies: 8
    Last Post: 13th January 2006, 14:52
  5. RemoveRows
    By Untersander in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2006, 09:44

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.