QThread works on Win7 and fails on WinXP
I have written a small application that starts a thread for sound input. I compile the code with Visual Studio 2010 prof. and Qt 4.8.0 (from the library installation package). The programm runs flawlessly on Win7 but fails on XP with the following message:
QThread::start: failed to create thread (Das Ger?t erkennt den Befehl nicht.)
[German XP, I would translate it like "The device does not recognise the command."]
It doesn't matter where I compile it. The binary compiled on Win7 works on Win7 and does not on WinXP, and the binary compiled on XP does not work on XP and does works on Win7. On both system all service packs for OS and Studio are installed.
I profiled the program with the process explorer and there occured several errors in connection with the Qt libraries. Would these messages help to solve the problem? Then I can post them here.
The GUI itself appears, I can push all the buttons and the labels and text boxes are filled correctly.
Does anyone have a clue what is going wrong here?
Welcome to devnet
Certainly, there might be a problem with Qt libraries not properly installed on your xp system.
However, it looks a bit more like the command you are trying to start does not exist on your xp machine. Are you sure that the syntax and everything shall be identical on your xp system?
The problem occurs if I call QThread::start() in a class derived from QThread.
class CAudioOut : public QThread
QAudioFormat m_format; QAudioOutput *m_audioOut;
CAudioOut::CAudioOut(void) : m_loop(true), m_audioOut(NULL)
// Set up the format, eg.
qRegisterMetaType<QAudio::State>("QAudio::State"); //start(QThread::TimeCriticalPriority); start();
Why does this work on Win7 and not on XP?
Did you see the "note":http://developer.qt.nokia.com/doc/qt-4.8/qthread.html#yieldCurrentThread beyond the documentation of QThread?
Furthermore, personally, I would not start the thread within the constructor. In my opinion it is better to create the object first and to start it subsequently.
Nevertheless, the note referenced above does suggest that subclassing of QThread is no longer recommended preference.
- QThread's contructor actually does not that many things. so I think it is ok to call QThread::start() in ctor in CAudioOut(though I do not know well about good design in this case).
- if win32, please check 'errno' thread local global variable's value after your calling to start(). In my case, abusing resource did result in such error sometimes(errno == ENOMEM)
[EDIT: list formatting, please use * without leading space instead of ' - ', Volker]
I played a little bit with the configuration and have a strange result now. It seems that VS 2010 does not like my implementation.
I downloaded 4.7.4 and 4.8.0 and compiled them with Studio 2005 and 2010. Then I compiled my application with these four variants. The 2005 version works with both 4.7.4 and 4.8.0, and both 2010 versions don't work.
Any idea why Studio 2010 cannot start the thread in the way Studio 2005 does?