c++ - Heap error in for loop using const type variable? -


for practice, using qt library trying select folder , list name of dicom files in folder. following code that:

int main(int argc, char* argv[]) {       qapplication app(argc, argv);     qstring filename = qfiledialog::getexistingdirectory();       if (filename.isempty())     {         std::cout << "got empty file!\n";     }     else     {         qstringlist namefilter;         qdir dir(filename);         namefilter << "*.dcm";         qfileinfolist list = dir.entryinfolist( namefilter, qdir::files );         int numberoffiles=list.count();          for(int i=0;i<numberoffiles;i++)         {             qstring filena=list[i].filename();             string a=filena.tostdstring();             cout<<a<<endl;          }     }    return 0; } 

here have found out function tostdstring, std::string qstring::tostdstring () const, gives heap error. know replacement rid of error use tolocal8bit().constdata(), i'm curious what's main reason behind heap error provided tostdstring. because const type , loop trying overwrite const variable everytime?

your code looks - make sure qt's dll files compiled same compiler (and same debug/release configuration) using.

to answer of questions:

is because const type , loop trying overwrite const variable everytime?

no, loop not trying overwrite const variable. const variable on right side of assingment operator, loop reading const variable, , doesn't overwritting (your a variable local variable visible inside loop's block, a different in each pass of loop).

even if try overwrite const variable, not compile - trying change const break in compile-time, , not in runtime.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -