Important: Please read the Qt Code of Conduct -

QThread stack-address

  • Greetings,

    I use Qt4.8 on Windows and I´m searching a way of getting the stack-address of a QThread or
    set the stack myself.

    With pthreads it´s possible to get/set the stack-pointer by pthread_attr_getstack() and
    Since QThreads are built upon pthreads there should be a solution but I only found
    QThread::setStackSize and I don´t like the idea of running a pthread in my QtApp only
    because of getting the address.

    The reason I need this is preventing the garbagecollection of my embedded interpreter
    which lives in a QThread from running amok ( )

    I would be really thankful for getting some help/advice (also if it´s just telling me that it´s not possible -.-)

  • Well it is based on pthread on UNIX systems but on native Windows threads on Windows. Qt is a cross-platform API and provides access to what can be used in a cross-platform way. The address of the stack must therefore not be portable, otherwise it would be part of the API.
    QThread was not really intended to be subclassed with @QThread::run()@ overloaded and used to fire up custom threads anyway. The initial design goal was to create a secondary event-loop in which QObjects could live and handle signals/events without blocking the main GUI thread. @QObject::moveToThread()@ is used for just that.
    So for your specific platform-related need, I think you'll have to go the platform-specific way and create your own pthread/native thread and use the platform API to achieve what you want.
    Hope this helps!

  • Helps a lot. Thank you very much for explaining rcari.

Log in to reply