Results 1 to 4 of 4

Thread: How to deal with foreign key in Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    2
    Qt products
    Qt4

    Default How to deal with foreign key in Qt

    Qt Code:
    1. else
    2. {
    3. query->prepare ("insert into Courses values (?,?,?)");
    4. query->bindValue (0,courseIDLine->text ());
    5. query->bindValue (1,courseNameLine->text ());
    6. query->bindValue (2,courseTeacherIDLine->text ());
    7.  
    8. successful=query->exec ();
    9.  
    10. }
    11.  
    12. if(successful)
    13. {
    14. closeInsertCourseDlg ();
    15. }
    16. else if(!errorMsg->isVisible ())
    17. {
    18. //cannot execute the statement
    19. }
    To copy to clipboard, switch view to plain text mode 

    but if the SQL statement doesn't satisfy the foreign key, the program will end unexpectedly, it will not just return a false

    how to change the code??

  2. #2
    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: How to deal with foreign key in Qt

    You change the code is a way that fixes whatever you have done that causes it to crash. You have not told us where it crashes or what you have done to isolate it. Run the code in your debugger and read the backtrace to find the source of the problem in your code.

    Qt will return false if the insert fails: it does not crash.

    If I assume for a moment that your code crashes somewhere in what you have presented then it will be at line 16 where the pointer errorMsg is invalid or null. This code will only be executed if the insert fails.

Similar Threads

  1. Replies: 1
    Last Post: 8th August 2011, 14:46
  2. How to deal with application-wide actions?
    By grayfox in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2011, 11:15
  3. Replies: 5
    Last Post: 31st December 2010, 11:49
  4. How to deal with shorcouts in many widgets
    By kazibi in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2010, 09:58
  5. Replies: 12
    Last Post: 23rd March 2007, 09:23

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.