Exception Triggered - Qt-Creator The inferior stopped because it triggered an exception.

本文探讨了在Qt Creator中遇到的堆栈溢出错误,重点在于识别错误原因——数组过大,提供了两种解决方案:调整数组大小和修改Qt Creator堆栈配置。此外,还介绍了如何通过修改.pro文件来增大默认栈大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qt系列文章目录

前言

#include "MainWindow.h"

#include <QApplication>
#include <QTime>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
//    w.show();

    QTime startTime = QTime::currentTime();
    int iCount[10000000] = {1};
    int item = 0;
    for(int i : iCount)
    {
        item = i;
    }

    QTime endTime = QTime::currentTime();
    qDebug() << startTime.msecsTo(endTime);

    return a.exec();
}

今天QtCreator调试时,写了一极其简单的程序,就是计算时间相减,调试时居然报错了:
Exception Triggered - Qt-Creator
The inferior stopped because it triggered an exception.
Stopped in thread 0 by:Exception an at 0xxxxxxxxxxxxx
code:0xcxxxxxxfd:stack-overflow,flags=0x0(first chance).
在这里插入图片描述
根据提示:应该是堆栈溢出了

一、错误原因

既然是堆栈溢出,就应该是指针非法,可我的程序里面没有指针鸭?仔细一看原来是我定义的数组太大了:

int iCount[10000000] = {1};

所以把数组改小一点就不会报错了,可如果您非要用怎么多数组怎么办了,
1.使用new在堆上分配大小了

在这里插入图片描述
2.修改QtCreator堆栈大小
打开pro文件,在最后添加:

二、使用步骤

网上说:修改Qt程序的默认栈大小
修改Qt工程配置文件pro
但是在我机器上依然报错
在这里插入图片描述
在这里插入图片描述

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0



QMAKE_LFLAGS += "/STACK:65536,4096"
#//设置栈保留大小65536K 提交大小4096K


SOURCES += \
    main.cpp \
    MainWindow.cpp

HEADERS += \
    MainWindow.h

FORMS += \
    MainWindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值