views:

63

answers:

2

How can I use windows.h in Qt application? After including it several errors like
"c:\Qt\4.4.3\include/QtCore/../../src/corelib/arch/qatomic_windows.h:387: error:
declaration of C function 'long int InterlockedCompareExchange(long int*, long int,
long int)' conflicts with
d:\old\mingw\bin../lib/gcc/mingw32/4.3.3/../../../../include/winbase.h:1681: error:
previous declaration 'LONG InterlockedCompareExchange(volatile LONG*, LONG,
LONG)' here"
appear.
All includes in order:
windows.h
iostream
QtCore
QtGui
QObject
QString
QFile
QProcess
QIODevice

EDIT: Problem disappear, Process.start() is now working, but I'm unable to say, what change made the difference. Thanks to all.

EDIT2: It's not that simple. I'll create new question.

EDIT3: The same code "QProcess Process; Process.start("notepad.exe");" works in main() and don't work in function called as a slot. Works only "QProcess *Process = new QProcess(); Process->start("notepad.exe");" I hate C++! Or should I hate Qt at the same time? It's 100 times simpler in Python. Literally, 100 times - several hours spent on various error messages. If only Python + Qt startup time were faster...

+1  A: 

Use proper version of mingw for your version of Qt. Qt 4.3 is not compatible with mingw >= 4

Kamil Klimek
MinGW version is 3.15.2, Qt version is 4.4.3
DSblizzard
But includes are from mingw 4: d:\old\mingw\bin../lib/gcc/mingw32/4.3.3/../../../../include/winbase.h:1681: error:
Kamil Klimek
Indeed. I used information from file MinGW\include\_mingw.h which is wrong for some reason.
DSblizzard
Glad I helped you
Kamil Klimek
+1  A: 

Its worth debugging why QProcess throws a QProcess::UnknownError - switching to use the native API directly does make the whole point of using QT - its cross platform afterall - a bit of a joke.

You are doing something that should work, that probably uses WinExec or system() already and as such, your attempt to launch notepad will just fail again.

Perhaps QT just needs the full path to notepad.exe? There are definitely times to write platform code in QT, this isn't one of them.

Chris Becke
"Perhaps QT just needs the full path to notepad.exe?" No, this doesn't work.
DSblizzard
Is this a stand alone QT program? or is it running in some kind of restricted mode on Vista/Windows 7? The only error I know of that CreateProcess might return is if the launch requires UAC elevation. But notepad.exe should not. So there has to be something else systematically wrong with your sample.
Chris Becke
Im curious- if you have the debug build of Qt it should be able to show you the entire call stack at the time the QProcess::Error got thrown. It should be failing on the basis of an error code returned from CreateProcess...
Chris Becke
1)Standalone program. 2)No, program not fails, but in LineEdit appears "5" after executing program with code " QProcess Process; Process.start("notepad.exe"); gMw->leBrowserPath->setText(QString::number(Process.error())); " even without error. Strange.
DSblizzard
Sory, but answer is not pointing out real problem
Kamil Klimek
But it pointed me in right direction. If anybody wants to dig this deeper they can ask the same question.
DSblizzard