Results 1 to 3 of 3

Thread: QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???

  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???

    Guys,
    Could someone tell me why the Progam Crashes. Here is the Code ...
    Qt Code:
    1. #include <qapplication.h>
    2. #include <qguardedptr.h>
    3. class Employee{
    4. public:
    5. Employee( const QString& strName, int iSal ){
    6. m_strName = strName;
    7. m_iSalary = iSal;
    8. }
    9.  
    10. QString name() const {
    11. return m_strName;
    12. }
    13. void setName( const QString& strName ){
    14. m_strName = strName;
    15. }
    16.  
    17. int salary() const {
    18. return m_iSalary;
    19. }
    20.  
    21. void setSalary( int iSal ) {
    22. m_iSalary = iSal;
    23. }
    24.  
    25. operator QString() const {
    26. return m_strName + ", " + QString::number( m_iSalary );
    27. }
    28.  
    29. private:
    30. QString m_strName;
    31. int m_iSalary;
    32. };
    33.  
    34.  
    35. int main(int iArgs, char* aszArgs[] ) {
    36. QApplication app( iArgs, aszArgs );
    37.  
    38. QMap< int, QGuardedPtr<Employee> > mapIdToEmployee;
    39. mapIdToEmployee[ 0 ] = new Employee( "Sunil", 6000 ); //Crashes ??
    40.  
    41. if( ! mapIdToEmployee[0] ){
    42. qWarning( "Employee Destroyed !!! " );
    43. }
    44. else{
    45. qWarning( ( static_cast<QString>(*mapIdToEmployee[0]) ).ascii() );
    46. }
    47. return 0;
    48. }
    To copy to clipboard, switch view to plain text mode 
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???

    Got the Answer

    [quote]
    The QGuardedPtr class is a template class that provides guarded pointers to QObjects.
    [quote]

    I Missed the Point - QObject
    We can't solve problems by using the same kind of thinking we used when we created them

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???

    Sorry for the Re Post
    We can't solve problems by using the same kind of thinking we used when we created them

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.