Click here to Skip to main content
15,892,072 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Clips Pin
Richard MacCutchan26-Apr-13 22:17
mveRichard MacCutchan26-Apr-13 22:17 
AnswerRe: Clips Pin
a.fatemeh26-Apr-13 22:22
a.fatemeh26-Apr-13 22:22 
GeneralRe: Clips Pin
Richard MacCutchan26-Apr-13 23:17
mveRichard MacCutchan26-Apr-13 23:17 
GeneralRe: Clips Pin
a.fatemeh26-Apr-13 23:26
a.fatemeh26-Apr-13 23:26 
QuestionHow can I capture screen without layered windows on Windows 8 Pin
thanh_bkhn25-Apr-13 23:50
professionalthanh_bkhn25-Apr-13 23:50 
QuestionCall stack trace using BOOST Pin
Shailesh H25-Apr-13 22:57
Shailesh H25-Apr-13 22:57 
Questionhow do I group test cases using BOOST Pin
Shailesh H25-Apr-13 22:55
Shailesh H25-Apr-13 22:55 
QuestionAbout preventing memory leaks Pin
Marco Bertschi25-Apr-13 22:27
protectorMarco Bertschi25-Apr-13 22:27 
I have a problem regarding file streams in Qt.
Basically, I read a file using this code:

int LoadSettings(){
    QFile* settingsFile = new QFile(storageFileLocation);

    if(!settingsFile->open(QIODevice::ReadOnly | QIODevice::Text)){
        return SettingsStorage::ErrorReadingFile;
    }

    QTextStream settingsFileStream(settingsFile);


    while(!settingsFileStream.atEnd()){
       QString fileLine;
       fileLine = settingsFileStream.readLine();
       QStringList splittedSettings = fileLine.split(SETTING_NAME_VALUE_SEPARATOR);
       int addingStatus = AddSettingIfNotExist(splittedSettings[SETTINGSARRAY_SETTINGNAMEPOS], splittedSettings[SETTINGSARRAY_SETTINGVALUEPOS]);
    }
    
    delete(settingsFile);//Memory access violation
    
    return SettingsStorage::Ok;
}


AFAIK I have to delete dynamically allocated memory myself. I dynamically allocate the QFile* "settingsFile" and want to delete it as soon as I do not need it anymore. So why do I get a memory access violation message?

I also know that Qt automatically disposes all allocated objects as soon as they derive from the QObject base class, but I want to write to the file later, therefore I have to clean up the allocated memory by myself.

Any help is greatly appreciated.

AnswerRe: About preventing memory leaks Pin
Freak3026-Apr-13 2:09
Freak3026-Apr-13 2:09 
GeneralRe: About preventing memory leaks Pin
Marco Bertschi26-Apr-13 3:25
protectorMarco Bertschi26-Apr-13 3:25 
AnswerRe: About preventing memory leaks Pin
Newbie0026-Apr-13 7:54
Newbie0026-Apr-13 7:54 
AnswerRe: About preventing memory leaks Pin
David Crow26-Apr-13 9:00
David Crow26-Apr-13 9:00 
AnswerRe: About preventing memory leaks Pin
jschell26-Apr-13 9:33
jschell26-Apr-13 9:33 
QuestionRegarding storing structures in database Pin
Member 789460125-Apr-13 19:03
Member 789460125-Apr-13 19:03 
AnswerRe: Regarding storing structures in database Pin
Richard MacCutchan25-Apr-13 22:23
mveRichard MacCutchan25-Apr-13 22:23 
AnswerRe: Regarding storing structures in database Pin
Marco Bertschi25-Apr-13 22:36
protectorMarco Bertschi25-Apr-13 22:36 
GeneralRe: Regarding storing structures in database Pin
Member 789460125-Apr-13 22:56
Member 789460125-Apr-13 22:56 
GeneralRe: Regarding storing structures in database Pin
Marco Bertschi25-Apr-13 23:16
protectorMarco Bertschi25-Apr-13 23:16 
GeneralRe: Regarding storing structures in database Pin
Jochen Arndt25-Apr-13 23:34
professionalJochen Arndt25-Apr-13 23:34 
GeneralRe: Regarding storing structures in database Pin
Member 789460125-Apr-13 23:41
Member 789460125-Apr-13 23:41 
GeneralRe: Regarding storing structures in database Pin
Jochen Arndt25-Apr-13 23:57
professionalJochen Arndt25-Apr-13 23:57 
AnswerRe: Regarding storing structures in database Pin
jschell26-Apr-13 9:36
jschell26-Apr-13 9:36 
GeneralRe: Regarding storing structures in database Pin
Member 789460129-Apr-13 1:00
Member 789460129-Apr-13 1:00 
GeneralRe: Regarding storing structures in database Pin
Member 78946011-May-13 0:09
Member 78946011-May-13 0:09 
Questionstrcat_memcpy Pin
khushboo gupta25-Apr-13 18:37
khushboo gupta25-Apr-13 18:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.