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