PDA

View Full Version : How to use Windows API with QT4?



MakSim345
19th March 2008, 14:46
Hi.
I have an _existing_ MS VC++ application, to where I have to "attach" a GUI, made by QT4.3.3
I can compile some simple GUIs with VS2005;
I can compile the existing app (let's say it is "time.exe", and it shows milliseconds on command prompt).
But I can not combine them together, in one project.
Here's an example of class in the time.exe which I can't compile from QT4 project:


class CTimer
{
public:
CTimer();
~CTimer();
void Start();
unsigned int GetElapsedTimeMs() const;
unsigned __int64 GetElapsedTimeMks() const;

private:
LARGE_INTEGER m_liFreq;
LARGE_INTEGER m_liStart;
LARGE_INTEGER m_liEnd;
};


implementation:


// Timer class
CTimer::CTimer()
{
::QueryPerformanceFrequency(&m_liFreq);
Start();
}

void CTimer::Start()
{
::QueryPerformanceCounter(&m_liStart);
}

unsigned int CTimer::GetElapsedTimeMs() const
{
LARGE_INTEGER liEnd;
::QueryPerformanceCounter(&liEnd);
return static_cast<unsigned int>((liEnd.QuadPart - m_liStart.QuadPart) * 1000 / m_liFreq.QuadPart);
}

unsigned __int64 CTimer::GetElapsedTimeMks() const
{
LARGE_INTEGER liEnd;
::QueryPerformanceCounter(&liEnd);
return static_cast<unsigned __int64>((liEnd.QuadPart - m_liStart.QuadPart) * 1000000 / m_liFreq.QuadPart);
}

// End of the class.


The QT project itself is very trivial - one button and one editbox, no point to show it here, I guess.

Example of errors i have if for example "winbase.h" file included:



1>moc_mywidget.cpp
1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\winbase.h(226) : error C2146: syntax error : missing ';' before identifier 'Internal'
1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\winbase.h(226) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


If someone could help me, explaining what settings I have to change on VS2005, any path to include, anything what may help, I'd appreciated it so much.
Thank you.

ChristianEhrlicher
19th March 2008, 15:02
It should work out of the box - maybe you forgot to include <windows.h> or something like this?