簡體   English   中英

如何解決此錯誤? 拋出'std :: bad_alloc'what()實例之后調用終止終止:std :: bad_alloc

[英]How I can fix this error? terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

這是代碼: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;

}

在這里我調用函數:

QString drum="/home/sunny/Desktop/QT/descarca";
        str=printDir2(drum,0);
        qDebug()<<str<<"acesta este drumul";

如何從終端修復此erorr:
拋出'std :: bad_alloc'what()實例后終止調用:std :: bad_alloc這是我運行此代碼時的終端: http : //s013.radikal.ru/i325/1501/e5/aade9346f0aa.png

您可能遇到了無限遞歸。

在調試器中運行程序。 如果使用gdb,則可以在run之前發出命令catch throw 然后,在引發異常時調試器將停止。 您可能需要up移動幾次才能看到代碼中的哪一行引發了異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM