Results 1 to 6 of 6

Thread: Crash on QString assignment

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Crash on QString assignment

    I would look at the lifetime of the "appData" pointer. You are simply storing it in your AutochargeData class. If it goes out of scope (e.g. is deleted) before the AutochargeData class instance does, then it is an invalid pointer and if used will cause a crash.

    Qt Code:
    1. while (query.next()) {
    2. setOrderID(query.value("increment_id").toString());
    3. setPayment(query.value("method").toString());
    4. setTotal(query.value("grand_total").toString());
    5. }
    To copy to clipboard, switch view to plain text mode 

    This code makes no sense. If the query result has more than one result in it, each time through the loop you are completely replacing the values in your member variables (which themselves should not be public members of the class). At the end of the loop they will simply contain the values from the last result. I don't imagine that is your intent.

    Also not really sure why you have derived AutochargeData from QWidget. It doesn't appear to have any user interface, so why? Deriving from QWidget (or QObject for that matter) is unnecessary for pure C++ classes used in a Qt application. If you do derive from a QObject-based class (like QWidget), then you need to include the "Q_OBJECT" macro at the top of the class definition:

    Qt Code:
    1. class MyClass : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyClass( QObject * parent );
    7.  
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 24th March 2016 at 15:40.

  2. The following user says thank you to d_stranz for this useful post:

    ce_nort (25th March 2016)

Similar Threads

  1. QString exception while executing assignment operation
    By Giox79 in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2015, 12:30
  2. Replies: 6
    Last Post: 29th December 2011, 18:37
  3. Comparing QString causes the program to crash .
    By ladiesfinger in forum Qt Programming
    Replies: 9
    Last Post: 6th November 2010, 17:17
  4. QString assignment
    By valgaba in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2010, 17:31
  5. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 14:28

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.