PDA

View Full Version : QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???



sunil.thaha
16th March 2006, 06:34
Guys,
Could someone tell me why the Progam Crashes. Here is the Code ...


#include <qapplication.h>
#include <qguardedptr.h>
class Employee{
public:
Employee( const QString& strName, int iSal ){
m_strName = strName;
m_iSalary = iSal;
}

QString name() const {
return m_strName;
}
void setName( const QString& strName ){
m_strName = strName;
}

int salary() const {
return m_iSalary;
}

void setSalary( int iSal ) {
m_iSalary = iSal;
}

operator QString() const {
return m_strName + ", " + QString::number( m_iSalary );
}

private:
QString m_strName;
int m_iSalary;
};


int main(int iArgs, char* aszArgs[] ) {
QApplication app( iArgs, aszArgs );

QMap< int, QGuardedPtr<Employee> > mapIdToEmployee;
mapIdToEmployee[ 0 ] = new Employee( "Sunil", 6000 ); //Crashes ??

if( ! mapIdToEmployee[0] ){
qWarning( "Employee Destroyed !!! " );
}
else{
qWarning( ( static_cast<QString>(*mapIdToEmployee[0]) ).ascii() );
}
return 0;
}

sunil.thaha
16th March 2006, 06:50
Got the Answer

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

I Missed the Point - QObject

sunil.thaha
16th March 2006, 07:09
Sorry for the Re Post