That usually means that "this" is not a valid object.
I.e. that you are calling a method on a pointer that does not actual point to a valid object.
E.g. an uninitialized pointer or a deleted pointer.
Cheers,
_
That usually means that "this" is not a valid object.
I.e. that you are calling a method on a pointer that does not actual point to a valid object.
E.g. an uninitialized pointer or a deleted pointer.
Cheers,
_
ce_nort (25th March 2016)
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:
while (query.next()) { setOrderID(query.value("increment_id").toString()); setPayment(query.value("method").toString()); setTotal(query.value("grand_total").toString()); }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:
{ Q_OBJECT public: ... }To copy to clipboard, switch view to plain text mode
Last edited by d_stranz; 24th March 2016 at 15:40.
ce_nort (25th March 2016)
Thanks for all the info, I am definitely new at this and self-taught/teaching so it is very helpful. I actually do have the "Q_OBJECT" macro in at the top of the class definition, I just left it out of the copy and paste. I'm not using signals and slots in this class, but I generally add it by default (bad idea?). I agree that the while loop would make no sense if the query returned more than one set of values, but it does not. There should be only one set of data to assign to the member variables, and the while loop was my understanding of how to check that the query returned successfully. I certainly don't claim that this is well written - I'm still learning what that looks like. It sounds like the general consensus is that the appData pointer is the issue and is probably deleted too soon elsewhere in the program. I'll check it out! Thanks again.
IMO, the problem isn't in Q_OBJECT (as long as AutochargeData does not use "Qt extras" - it is not an UI object, it declares no properties, slots or signals, etc.) The setOrderID() method is innocent. IMO, the problem is somewhere in the database. For starters, I recommend splitting the setOrderID() statement and seeing whether you pass and what values will the debugger show. Therefore:
Pleas, post your findings.Qt Code:
setOrderID(str); // does it pass? What happens?To copy to clipboard, switch view to plain text mode
I got this figured out shortly before you posted. As predicted, it was something obvious that I was missing. I had created an instance of AutochargeData in the Mainwindow class, but was trying to use it in a different class without creating another instance of it. So it was invalid, as was guessed by the other posts in this thread. Thanks everyone!
Bookmarks