Results 1 to 20 of 23

Thread: Constructor call problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    Well, my answers:

    1. Qt Code:
      1. QList<CMerchandizeOrder*> orders=shoppingCartModel()->orders();
      To copy to clipboard, switch view to plain text mode 
      gets full ist of previous orders in model, so I can check if processed order is already in list of orders so I can then update quantity (+1) and subtotal of order (recalculate quantity*price=subtotal)
    2. query.next() is executesd excalty ONCE
    3. here is addEntry code:
      Qt Code:
      1. void CShoppingCartWidget::addEntry(structOrder& order)
      2. {
      3. // debug block
      4. qDebug() << "order.iMerchandizeID=" << order.iMerchandizeID;
      5. qDebug() << "order.iMerchandizeQuantity=" << order.iMerchandizeQuantity;
      6. qDebug() << "order.rMerchandizePrice=" << order.rMerchandizePrice;
      7. qDebug() << "order.rSubtotal=" << order.rSubtotal;
      8. qDebug() << "order.strDisplayString=" << order.strDisplayString;
      9. qDebug() << "order.strMerchandizeName=" << order.strMerchandizeName;
      10. // **** END of debug block
      11.  
      12. QList<CMerchandizeOrder*> orders=shoppingCartModel()->orders();
      13. CMerchandizeOrder* tempOrder=new CMerchandizeOrder(order);
      14. Q_CHECK_PTR(tempOrder);
      15.  
      16. /*
      17.   tempOrder.iMerchandizeID=order.iMerchandizeID;
      18.   tempOrder.iMerchandizeQuantity=order.iMerchandizeQuantity;
      19.   tempOrder.rMerchandizePrice=order.rMerchandizePrice;
      20.   tempOrder.rSubtotal=order.rSubtotal;
      21.   tempOrder.strDisplayString=order.strDisplayString;
      22.   tempOrder.strMerchandizeName=order.strMerchandizeName;
      23. */
      24.  
      25. if (!orders.contains(tempOrder))
      26. {
      27. // new merchandize
      28. shoppingCartModel()->insertRows(0, 1, QModelIndex());
      29. QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
      30. shoppingCartModel()->setData(index,
      31. //tempOrder.orderValues().strDisplayString,
      32. tempOrder->orderValues().strDisplayString,
      33. Qt::EditRole);
      34. }
      35. else
      36. {
      37. // merchandize exists, update quantity and subtotal
      38. }
      39. }
      To copy to clipboard, switch view to plain text mode 

    So, I was working on the base of qt 4.4.0 example and there the object is created in same fashion like in my module ...
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Constructor call problem

    will have to go thru ur code all again []

    one thing i can suggest for the time being,,,
    if ur code is going in constructor, are u able to pur breakpoint and see the call stack.
    It will give u an idea wher the object is being created

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    Quote Originally Posted by aamer4yu View Post
    will have to go thru ur code all again []

    one thing i can suggest for the time being,,,
    if ur code is going in constructor, are u able to pur breakpoint and see the call stack.
    It will give u an idea wher the object is being created
    I do not understand right now what do you mean, we already saw the object is being made in the wasy as it should THE FIRST TIME, but I cannot crack why are constructors (both) being called 4 times (as you saw from debug messages). I double checked and I confirm query.exec() is executed only ONCE.
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Constructor call problem

    I mean,,, are u able to SET A BREAKPOINT in the constructor now ???

    if yes,,, set the breakpoint... and see from the call stack from where the code was called

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    The Eclipse IDE lets me set the breakpoint in constructor, but the breakpoint is never reached ...
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Constructor call problem

    then how come you are able to get qDebug messages from the ctor

  7. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    Quote Originally Posted by aamer4yu View Post
    then how come you are able to get qDebug messages from the ctor
    I've setup breakpoint in the next line of code after constructor and then I copied messages from debug console. Messages stay in debug console after exiting from constructor ...
    Qt 5.3 Opensource & Creator 3.1.2

  8. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    If I setup breakpoint one line before CMerchandizeOrder constructor call and then try to step into CMerchandize constructor call I get something very weird, the dialog box shows which source file to choose to go into and there are several choices, which are all the same - qbytearray.h. I've enclosed a screenshot for better understanding. Is this maybe somekind of qt 4.4.0 bug?!
    Attached Images Attached Images
    Qt 5.3 Opensource & Creator 3.1.2

  9. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    Gurus like jacek, jpn, wysotta and other pleeeeeease help me!!!!
    Qt 5.3 Opensource & Creator 3.1.2

  10. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    I've changed the code in addEntry() to:
    Qt Code:
    1. void CShoppingCartWidget::addEntry(structOrder& order)
    2. {
    3. // debug block
    4. qDebug() << "order.iMerchandizeID=" << order.iMerchandizeID;
    5. qDebug() << "order.iMerchandizeQuantity=" << order.iMerchandizeQuantity;
    6. qDebug() << "order.rMerchandizePrice=" << order.rMerchandizePrice;
    7. qDebug() << "order.rSubtotal=" << order.rSubtotal;
    8. qDebug() << "order.strDisplayString=" << order.strDisplayString;
    9. qDebug() << "order.strMerchandizeName=" << order.strMerchandizeName;
    10. // **** END of debug block
    11.  
    12. QList<CMerchandizeOrder*> orders=shoppingCartModel()->orders();
    13. //CMerchandizeOrder* tempOrder=new CMerchandizeOrder(order);
    14. //Q_CHECK_PTR(tempOrder);
    15. CMerchandizeOrder tempOrder(order);
    16.  
    17. /*
    18.   tempOrder.iMerchandizeID=order.iMerchandizeID;
    19.   tempOrder.iMerchandizeQuantity=order.iMerchandizeQuantity;
    20.   tempOrder.rMerchandizePrice=order.rMerchandizePrice;
    21.   tempOrder.rSubtotal=order.rSubtotal;
    22.   tempOrder.strDisplayString=order.strDisplayString;
    23.   tempOrder.strMerchandizeName=order.strMerchandizeName;
    24. */
    25.  
    26. if (!orders.contains(&tempOrder))
    27. {
    28. // new merchandize
    29. shoppingCartModel()->insertRows(0, 1, QModelIndex());
    30. QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
    31. shoppingCartModel()->setData(index,
    32. tempOrder.orderValues().strDisplayString,
    33. //tempOrder->orderValues().strDisplayString,
    34. Qt::EditRole);
    35. }
    36. else
    37. {
    38. // merchandize exists, update quantity and subtotal
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 
    and I get same result.
    Qt 5.3 Opensource & Creator 3.1.2

  11. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Constructor call problem

    The problem has been solved, I've checked all sources related to table widget and I found some merchandize order field reset code from other developer that I did not have been aware god damn!!!! Stupid, stupid, stupid! Anyway, thanks all repliers for your time. But gdb still has problems with setting breakpoints in constructors ...
    Qt 5.3 Opensource & Creator 3.1.2

  12. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Constructor call problem

    relief for me too,,,, i was also begining to bang my head
    i told ya,, u must be overriding somewher

  13. The following user says thank you to aamer4yu for this useful post:

    MarkoSan (28th May 2008)

Similar Threads

  1. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.