I start coding a small qt application to compute checksums. After the unthreaded code run fine I moved to a more responsive way since the mainwindow blocks while computing a hash of a bigger file.
But calling the run() method failes for unknown reason. I even cleared out the run-method completely. No matter what I do: SIGSEV.
Other threaded code from the qt help compile and run without problems – even threaded code in other apps I coded still run, but this not:
the header:
#include <QThread>
class Hasher : public QThread
{
Q_OBJECT
public:
Hasher();
void computeHash();
protected:
void run();
};
the implementation
#include "hasher.h"
Hasher::Hasher()
{
}
void Hasher::computeHash() {
start();
}
void Hasher::run() {
// compute the hash, but for now simply return
}
caller
Hasher h
h.computeHash();
As I said above all works well without threads but crashes when using threads.
I am using QT 4.7.3 on a 64bit ARCH-Linux – and I am really clueless about this.
Maybe someone can help.
If you do like this your thread will be created on stack and it will be destroyed while the thread is still running !
NeilMonday’s example works because he has a
return a.exec();in his code which keeps Hasher thread alive on the stack. So you have to make your thread live longer.Hasher* h = new Hasher ();or