[SOLVED] Thread Finalizing



  • Hello my dear friends
    I have a simple scenario

    I want to start a thread using QThread class and finalize it when ever I want
    @
    class PlayerManager : public QThread@

    ....

    @PlayerManager::PlayerManager(QObject *parent) :
    QThread(parent)
    {
    _isFinalized = false;
    connect(this, &QThread::finished, this, &QThread::deleteLater);
    start();
    }@

    in run method do some tasks

    @void PlayerManager::run()
    {

    while (!(IsFinalized())) {
        _mutex.lock();
        //Do something
        _mutex.unlock();
        usleep(50);
    }
    

    @
    and after that finalize it

    @void PlayerManager::Finalize()
    {
    _mutex.lock();
    _isFinalized = true;
    _mutex.unlock();
    }

    bool PlayerManager::IsFinalized()
    {
    bool result;
    _mutex.lock();
    result = _isFinalized;
    _mutex.unlock();
    return result;
    }
    @
    I get instance of this class here

    @int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    PlayerManager pm;
    usleep(1000000);
    pm.Finalize();
    return a.exec();
    }
    @

    --but i recive this signal
    SIGABRT
    thank you



  • oops I found the answer

    @
    PlayerManager pm;
    @

    the correct

    @
    PlayerManager* pm = new PlayerManager();
    @



  • Please,,Write [SOLVED] before Title if You found the answer,otherwise share your problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.