Click here to Skip to main content
15,843,623 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Clips Pin
Richard MacCutchan26-Apr-13 23:17
mveRichard MacCutchan26-Apr-13 23:17 
AnswerRe: Clips Pin
a.fatemeh26-Apr-13 23:22
a.fatemeh26-Apr-13 23:22 
GeneralRe: Clips Pin
Richard MacCutchan27-Apr-13 0:17
mveRichard MacCutchan27-Apr-13 0:17 
GeneralRe: Clips Pin
a.fatemeh27-Apr-13 0:26
a.fatemeh27-Apr-13 0:26 
QuestionHow can I capture screen without layered windows on Windows 8 Pin
thanh_bkhn26-Apr-13 0:50
professionalthanh_bkhn26-Apr-13 0:50 
QuestionCall stack trace using BOOST Pin
Shailesh H25-Apr-13 23:57
Shailesh H25-Apr-13 23:57 
Questionhow do I group test cases using BOOST Pin
Shailesh H25-Apr-13 23:55
Shailesh H25-Apr-13 23:55 
QuestionAbout preventing memory leaks Pin
Marco Bertschi25-Apr-13 23:27
protectorMarco Bertschi25-Apr-13 23: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 3:09
Freak3026-Apr-13 3:09 
GeneralRe: About preventing memory leaks Pin
Marco Bertschi26-Apr-13 4:25
protectorMarco Bertschi26-Apr-13 4:25 
AnswerRe: About preventing memory leaks Pin
Newbie0026-Apr-13 8:54
Newbie0026-Apr-13 8:54 
AnswerRe: About preventing memory leaks Pin
David Crow26-Apr-13 10:00
David Crow26-Apr-13 10:00 
AnswerRe: About preventing memory leaks Pin
jschell26-Apr-13 10:33
jschell26-Apr-13 10:33 
QuestionRegarding storing structures in database Pin
Member 789460125-Apr-13 20:03
Member 789460125-Apr-13 20:03 
AnswerRe: Regarding storing structures in database Pin
Richard MacCutchan25-Apr-13 23:23
mveRichard MacCutchan25-Apr-13 23:23 
AnswerRe: Regarding storing structures in database Pin
Marco Bertschi25-Apr-13 23:36
protectorMarco Bertschi25-Apr-13 23:36 
GeneralRe: Regarding storing structures in database Pin
Member 789460125-Apr-13 23:56
Member 789460125-Apr-13 23:56 
GeneralRe: Regarding storing structures in database Pin
Marco Bertschi26-Apr-13 0:16
protectorMarco Bertschi26-Apr-13 0:16 
GeneralRe: Regarding storing structures in database Pin
Jochen Arndt26-Apr-13 0:34
professionalJochen Arndt26-Apr-13 0:34 
GeneralRe: Regarding storing structures in database Pin
Member 789460126-Apr-13 0:41
Member 789460126-Apr-13 0:41 
GeneralRe: Regarding storing structures in database Pin
Jochen Arndt26-Apr-13 0:57
professionalJochen Arndt26-Apr-13 0:57 
AnswerRe: Regarding storing structures in database Pin
jschell26-Apr-13 10:36
jschell26-Apr-13 10:36 
GeneralRe: Regarding storing structures in database Pin
Member 789460129-Apr-13 2:00
Member 789460129-Apr-13 2:00 
GeneralRe: Regarding storing structures in database Pin
Member 78946011-May-13 1:09
Member 78946011-May-13 1:09 
Questionstrcat_memcpy Pin
khushboo gupta25-Apr-13 19:37
khushboo gupta25-Apr-13 19: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.