Results 1 to 13 of 13

Thread: QList of my own class (append)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Johannesburg, South Africa
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QList of my own class (append)

    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

    Qt Code:
    1. Transaction::Transaction(int n, double p):
    2. m_NoOfItems(n), m_PricePerItem(p), m_Transactions(QDate::currentDate())
    3. {};
    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.

    Qt Code:
    1. void Product::sell(int n) {
    2. if (m_NoOfItems < n)
    3. cout << "Transaction failed - insufficient stock" <<endl;
    4. else {
    5. m_NoOfItems -= n;
    6. m_Transactions.append(Transaction(3,1.00));
    7.  
    8. cout <<"Size of array:" << m_Transactions.size() <<endl;
    9. }
    10.  
    11. }
    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?
    Last edited by april26; 19th March 2011 at 16:59.

Similar Threads

  1. Does QList use copy constructor when some element append to it?
    By indomie_seleraku in forum Qt Programming
    Replies: 7
    Last Post: 17th December 2010, 19:47
  2. QList append() problem
    By reuabreliz in forum Qt Programming
    Replies: 6
    Last Post: 6th January 2010, 13:27
  3. error with QList with a class
    By john_god in forum Newbie
    Replies: 7
    Last Post: 12th January 2009, 21:48
  4. Cannot append to QFile using QIODevice::Append
    By philwinder in forum Qt Programming
    Replies: 4
    Last Post: 17th November 2008, 09:09
  5. using Qlist with a class
    By Havard in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2007, 19:38

Tags for this Thread

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.