HI frdz...
In my application I need to attatch files dynamically from the phone memory, memory card upon user selection option for that I did bellow code.. For first time it is working fine.. but when we call the screen for the 2nd time the application is terminating.. Could any body help me where am I doing wrong.


QString CreateFollowView::attachFiles() {
TFileName folder;

tAttachment->setFocus();
// Create select memory dialog
CAknMemorySelectionDialog::TMemory memory= CAknMemorySelectionDialog::EPhoneMemory;
for (; {
CAknMemorySelectionDialog* memDlg = CAknMemorySelectionDialog::NewL(ECFDDialogTypeSelect, ETrue);
// Create select folder dialog
CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeSelect);
// some dialog customizations:
dlg->SetTitleL(_L("Select folder"));
dlg->SetRightSoftkeyRootFolderL(_L("Back")); // for root folder
TBool result = EFalse;
if (memDlg->ExecuteL(memory) == CAknFileSelectionDialog::ERightSoftkey) {
// cancel selection
break;
}
if (memory == CAknMemorySelectionDialog::EMemoryCard) {
folder = PathInfo::MemoryCardRootPath();
} if(memory == CAknMemorySelectionDialog::EPhoneMemory){
folder = PathInfo::PhoneMemoryRootPath();
}
if (dlg->ExecuteL(folder)) {
QString folderPath((QChar*) folder.Ptr(), folder.Length());
folderPath = QDir::toNativeSeparators(folderPath);
QFile file(folderPath);
intFileSize = file.size();
int intSize = ceil((float) file.size() / 1024.0);
QString strLabelText;
strLabelText += "(" + QString::number(intSize) + "KB)";
fileName.clear();
fileName.append(folderPath);
folderPath.append(strLabelText);
tAttachment->setText(folderPath);
tAttachment->setStyleSheet(QString::fromUtf8(
"background-color: rgb(255,255,255); color: rgb(0,0,0);border-width: 2px; border-style: solid; border-color: rgb(164,193,236);"));
m_nFileFlag = 1;
int nWidth = 0;
QString strSubjectText;
strSubjectText = tAttachment->toPlainText();
makeAutoExtendableText(strSubjectText, tAttachment->width() - 12, font);
QStringList lstSubject = strSubjectText.split("\n");
nWidth = lstSubject.length() - 1;
if (lblFileError->isHidden()) {
tAttachment->setGeometry(0, line_2->geometry().bottom() + 1, g_nScreenWidth, (nWidth * 17) + 25);
} else {
lblFileError->setGeometry(0, line_2->geometry().bottom(), g_nScreenWidth, 20);
line_4->setGeometry(0, lblFileError->geometry().bottom(), g_nScreenWidth, 1);
tAttachment->setGeometry(0, line_4->geometry().bottom() + 1, g_nScreenWidth, (nWidth * 17) + 25);
}
lastScrollPosition = tAttachment->geometry().bottom();
if (lastScrollPosition + 3 >= (g_nScreenHeight - 50)) {
lastLabelPosition += (lastScrollPosition - ((g_nScreenHeight - 50))) + 3;
labelWidget->scroll(0, (-(((lastScrollPosition - ((g_nScreenHeight - 50))) + 3))));
m_pScrollBar->setSliderPosition(lastLabelPosition);
} else {
if (lblBody->geometry().top() < 0) {
if ((lblBody->geometry().top() * -1) > (((g_nScreenHeight - 50) - lastScrollPosition) - 3)) {
lastLabelPosition -= ((g_nScreenHeight - 50) - lastScrollPosition) - 3;
labelWidget->scroll(0, (((g_nScreenHeight - 50) - lastScrollPosition) - 3));
m_pScrollBar->setSliderPosition(lastLabelPosition);
} else {
lastLabelPosition = 0;
labelWidget->scroll(0, (lblBody->geometry().top() * -1));
m_pScrollBar->setSliderPosition(lastLabelPosition);
}
} else {
lastLabelPosition = 0;
m_pScrollBar->setSliderPosition(lastLabelPosition);
}
}
if (tAttachment->geometry().bottom() > (g_nScreenHeight - 50) || lblBody->geometry().top() < 0) {
m_pScrollBar->setVisible(true);
m_pScrollBar->setMinimum(0);
m_pScrollBar->setMaximum((tAttachment->geometry().bottom() - (g_nScreenHeight - 50)) + (lblBody->geometry().top() * -1));
m_pScrollBar->setRange(0, (tAttachment->geometry().bottom() - (g_nScreenHeight - 50)) + (lblBody->geometry().top() * -1));
m_pScrollBar->setSliderPosition(lastLabelPosition);
labelWidget->setGeometry(0, 25, g_nScreenWidth - 8, g_nScreenHeight - 28);
} else {
m_pScrollBar->setMinimum(0);
m_pScrollBar->setVisible(false);
labelWidget->setGeometry(0, 25, g_nScreenWidth, g_nScreenHeight - 28);
}
tAttachment->setFocus();
QMessageBox::information(0,"","end");
delete memDlg;
delete dlg;
memory=CAknMemorySelectionDialog::EPhoneMemory;
return folderPath;
}
}
}return NULL;
}