Results 1 to 13 of 13

Thread: Probelm after porting from Qt 3.3.4 to Qt 4.2.2

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Probelm after porting from Qt 3.3.4 to Qt 4.2.2

    Ok, no time to attach:
    childobject.cpp
    Qt Code:
    1. #include "childObject.h"
    2.  
    3. Atom::Atom(QObject *parent)
    4. :QObject(parent)
    5. {
    6. setObjectName( "Atom" );
    7. isSelected = false;
    8. }
    9.  
    10. Atom::~Atom()
    11. {}
    12.  
    13. void Atom::deleteSelected()
    14. {
    15. if( isSelected )
    16. delete this;
    17. }
    18. void Atom::setSelected( bool flag )
    19. {
    20. isSelected = flag;
    21. }
    22.  
    23. Bond::Bond(QObject *parent)
    24. :QObject(parent)
    25. {
    26. setObjectName( "Bond" );
    27. isSelected = false;
    28. }
    29.  
    30. Bond::~Bond()
    31. {
    32. emit beingDeleted(this);
    33. }
    34.  
    35. void Bond::setSelected( bool flag )
    36. {
    37. isSelected = flag;
    38. }
    39.  
    40. bool Bond::selected()
    41. {
    42. return isSelected;
    43. }
    44.  
    45. void Bond::deleteSelected()
    46. {
    47. if( isSelected )
    48. {
    49. delete this;
    50. }
    51. }
    52. Ring::Ring(QObject *parent)
    53. :QObject(parent)
    54. {
    55. setObjectName( "Ring" );
    56. isSelected = false;
    57. }
    58.  
    59. Ring::~Ring()
    60. {}
    61.  
    62. void Ring::setSelected( bool flag )
    63. {
    64. isSelected = flag;
    65. }
    66.  
    67. bool Ring::selected()
    68. {
    69. return isSelected;
    70. }
    71.  
    72. void Ring::deleteSelected()
    73. {
    74. if( isSelected )
    75. {
    76. delete this;
    77. }
    78. }
    79.  
    80. void Ring::addBond(Bond * b)
    81. {
    82. connect( b, SIGNAL(beingDeleted(QObject *)),
    83. this, SLOT(childBeingDeleted(QObject *)) );
    84. }
    85.  
    86. void Ring::childBeingDeleted(QObject *)
    87. {
    88. /*delete this;*/
    89. }
    To copy to clipboard, switch view to plain text mode 
    parentobject.cpp
    Qt Code:
    1. #include "parentobject.h"
    2. #include "childObject.h"
    3. #include <qobject>
    4.  
    5. Molecule::Molecule(QObject *parent)
    6. : QObject(parent)
    7. {
    8. isSelected = false;
    9. _ring = 0;
    10. }
    11.  
    12. Molecule::~Molecule()
    13. {
    14. if( isSelected ){
    15. isSelected = false;
    16. }
    17. }
    18.  
    19. void Molecule::createRing( Bond* b)
    20. {
    21. if( !_ring )
    22. {
    23. _ring = new Ring( this );
    24. }
    25. _ring->addBond(b);
    26. }
    27.  
    28. void Molecule::deleteSelected()
    29. {
    30. if( isSelected ){
    31. delete this;
    32. return;
    33. }
    34. QList<QObject*> list;
    35. QObject *obj;
    36. list = children();
    37.  
    38. foreach( obj, children() )
    39. {
    40. if( obj )
    41. {
    42. qDebug( obj->objectName().toAscii().constData() );
    43. if( obj->objectName() == QString("Bond") )
    44. {
    45. bool sel = ((Bond*)obj)->selected();
    46. if( sel )
    47. {
    48. list.removeAll( obj );
    49. ((Bond*)obj)->deleteSelected();
    50. obj = NULL;
    51. }
    52. }
    53. }
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 
    You had several problem there, so I corrected them:
    - a QObject automatically deletes its children, so no need to connect and delete the Ring
    - QObjectList and QObjectListIt were replaced ( by me ).
    - I added a selected() function. It just returns is selected.

    Note: I'm surprised this worked in Qt3

    EDIT: some of the code I posted might be redundant. So feel free to remove those parts.

    Regards
    Last edited by marcel; 30th May 2007 at 08:56.

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.