This is the code: Function :
QString printDir2(QString path, int level)
{
int check =1;
QDir folder(path);
QString space;
QString buffer;
qDebug() <<"nivelul 1 \n";
for(int i=0; 1<level; i++)
space +=" ";
qDebug() <<"nivelul 2 \n";
foreach(QFileInfo temp , folder.entryInfoList())
{
if(check > 2)
{
qDebug() <<"nivelul 4 \n";
buffer += space + temp.absoluteFilePath() + "\n";
if(temp.isDir())
buffer += printDir2(temp.absoluteFilePath(), ++level);
}
check++;
qDebug() <<"nivelul 3 \n";
}
return buffer;
}
and here i call the function:
QString drum="/home/sunny/Desktop/QT/descarca";
str=printDir2(drum,0);
qDebug()<<str<<"acesta este drumul";
How to fix this erorr from terminal:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc this is the terminal when i run ths code: http://s013.radikal.ru/i325/1501/e5/aade9346f0aa.png
You may have run into infinite recursion.
Run your program in the debugger. If you use gdb, you can issue the command catch throw
before run
. Then the debugger will stop when the exception is thrown. You may have to move up
a few times to see which line in your code threw the exception.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.