DSblizzard
DSblizzard

Reputation: 4149

Qt error while including <windows.h>

How can I use windows.h in Qt application? After including it I get 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  

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.

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 doesn't work in function called as a slot. Works only QProcess *Process = new QProcess(); Process->start("notepad.exe");

Upvotes: 1

Views: 2978

Answers (2)

Chris Becke
Chris Becke

Reputation: 36026

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.

Upvotes: 1

Kamil Klimek
Kamil Klimek

Reputation: 13130

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

Upvotes: 1

Related Questions