I'm pretty new to Qt and C++ so I'm probably missing something obvious, but for the life of me I can't figure out what is going wrong. One of the classes in a program I wrote is causing a crash whenever I try to do a basic string assignment. See below (slightly pared down).
class AutochargeData
: public QWidget{
public:
AutochargeData
(appData
*appInfo,
QWidget *parent
= 0);
void getPaymentData
(QString orderID
);
private:
appData *appInfo;
};
class AutochargeData : public QWidget
{
public:
AutochargeData(appData *appInfo, QWidget *parent = 0);
QString orderNum;
QString paymentMethod;
QString total;
void setPayment(QString payment);
void setOrderID(QString orderID);
void setTotal(QString total);
void getPaymentData(QString orderID);
private:
appData *appInfo;
};
To copy to clipboard, switch view to plain text mode
So in the below code, I have tried many variations. I know the query is fine because I've used qDebug() to check the output. I have tried skipping the set functions and doing a direct assignment, I have tried using the "this" keyword, and I have even tried just assigning a random string directly to the variables.
AutochargeData
::AutochargeData(appData
*appInfo,
QWidget *parent
) :{
this->appInfo = appInfo;
}
void AutochargeData
::getPaymentData(QString orderID
) {
QString queryString
= "SELECT order_payment.method, order.increment_id, order.grand_total FROM order JOIN order_payment ON sales_flat_order.entity_id = order_payment.parent_id WHERE order.increment_id = '" + orderID
+ "';";
query.exec();
while (query.next()) {
setOrderID(query.value("increment_id").toString());
setPayment(query.value("method").toString());
setTotal(query.value("grand_total").toString());
}
}
void AutochargeData
::setPayment(QString payment
) {
paymentMethod = payment;
}
void AutochargeData
::setOrderID(QString orderID
) {
orderNum = orderID;
}
void AutochargeData
::setTotal(QString grandTotal
) {
total = grandTotal;
}
AutochargeData::AutochargeData(appData *appInfo, QWidget *parent) :
QWidget(parent)
{
this->appInfo = appInfo;
}
void AutochargeData::getPaymentData(QString orderID)
{
QString queryString = "SELECT order_payment.method, order.increment_id, order.grand_total FROM order JOIN order_payment ON sales_flat_order.entity_id = order_payment.parent_id WHERE order.increment_id = '" + orderID + "';";
QSqlQuery query(queryString, QSqlDatabase::database("db"));
query.exec();
while (query.next()) {
setOrderID(query.value("increment_id").toString());
setPayment(query.value("method").toString());
setTotal(query.value("grand_total").toString());
}
}
void AutochargeData::setPayment(QString payment)
{
paymentMethod = payment;
}
void AutochargeData::setOrderID(QString orderID)
{
orderNum = orderID;
}
void AutochargeData::setTotal(QString grandTotal)
{
total = grandTotal;
}
To copy to clipboard, switch view to plain text mode
Any time I tried to assign a string to the orderNum, paymentMethod, or total variables, the program crashes. The debugger is ending on
QString::operator=(const char*)
To copy to clipboard, switch view to plain text mode
in the qstring.h file. As I mentioned, I am relatively new at this so it may be something obvious that I am missing. But after multiple hours of googling and trying different variations, I am stumped. Any thoughts would be much appreciated, and please let me know if there's more information that would be helpful.
Bookmarks