How to increase stack size for a thread in Qt - QT

2019-08-15 08:19发布

From the question: SQLite stack overflow when running a bulk INSERT OR REPLACE with 500 rows: why?, I need to increase the stack size for a certain thread in Qt.

I would like this to be cross-platform, but I am initially starting by trying to get it working on Windows.

Unfortunately, nothing I have tried to do successfully increases the stack size for the thread in question. (I measure the stack size by adding code to evaluate the current stack size (see link above), and observing that a stack overflow crash occurs at 1 MB, which does not reflect the stack size I am trying to set.)

I have tried the following things:

In Qt's .pro file for the project:

QMAKE_CXXFLAGS += /F 32000000
QMAKE_LFLAGS   += /STACK:32000000

In the source code, the line before the QThread::start() function is called on the thread:

work_queue_manager_thread.setStackSize(static_cast<uint>(stackSize));

(where work_queue_manager_thread is the QThread instance, and stackSize is 32000000).

I have tried both of the above attempts individually, and I have tried them together. The result is the same: the stack size remains at 1 MB for the thread in question. It does not reflect my desired stack size. I am unable to set the stack size for my Qt thread.

How do I actually set the stack size for a Qt thread to 32000000 - and in a way that works across Windows and OS X?

Thanks.

1条回答
孤傲高冷的网名
2楼-- · 2019-08-15 08:25

Turns out the QMAKE flags indicated in the question work.

However, using Qt Creator, performing a Clean All and rebuild does not work to pick up the new flags. Instead, the entire Debug/Release folder must be deleted, and then a rebuild performed. Then it works.

But the flags only work for Windows - I may update this answer when I determine the OS X flags, hopefully shortly.

Nonetheless, the flags work as indicated.

查看更多
登录 后发表回答