I have a Class "Transaction" with 3 members (Int, double, QDate). The instances are created using a constructor that provides the first two variables, and QDate is the current date.
The constructor is
Transaction::Transaction(int n, double p):
m_NoOfItems
(n
), m_PricePerItem
(p
), m_Transactions
(QDate::currentDate()){};
Transaction::Transaction(int n, double p):
m_NoOfItems(n), m_PricePerItem(p), m_Transactions(QDate::currentDate())
{};
To copy to clipboard, switch view to plain text mode
I have a Class Product which has a private member: QList<Transaction> m_Transactions. It is not a pointer class.
When products are sold the method sell(int n) is called, and it is meant to create a Transaction record and append it to the QList m_Transactions. I have tried for about 5 hours now and after trying many of the approaches offered by other forums I can't find a way to create a Transaction. Or possibly I am creating the transaction and each transaction is overwriting. I have been using the size of m_Transactions to judge whether the transaction is being stored, because I can't traverse the list either.
void Product::sell(int n) {
if (m_NoOfItems < n)
cout << "Transaction failed - insufficient stock" <<endl;
else {
m_NoOfItems -= n;
m_Transactions.append(Transaction(3,1.00));
cout <<"Size of array:" << m_Transactions.size() <<endl;
}
}
void Product::sell(int n) {
if (m_NoOfItems < n)
cout << "Transaction failed - insufficient stock" <<endl;
else {
m_NoOfItems -= n;
m_Transactions.append(Transaction(3,1.00));
cout <<"Size of array:" << m_Transactions.size() <<endl;
}
}
To copy to clipboard, switch view to plain text mode
I am a beginner with both C++ and Qt and the reference material and error messages don't make much sense to me. I am working by trial and error (a great MANY errors). I can append, print and work perfectly with a QList <int> but not with my own class.
I am getting quite desperate, as once I get this to work I then have another QList of pointers which looks even worse! Please can anyone help?
Bookmarks