[英]How I can fix this error? terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
This is the code: Function : 这是代码: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: 如何从终端修复此erorr:
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 抛出'std :: bad_alloc'what()实例后终止调用:std :: bad_alloc这是我运行此代码时的终端: 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
. 如果使用gdb,则可以在
run
之前发出命令catch throw
。 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. 您可能需要
up
移动几次才能看到代码中的哪一行引发了异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.