PDA

View Full Version : WinApi tool with qt



naimatropical
21st September 2016, 20:52
Hi i am trying to do one winapi application in qt but it doesnt work. Someone can check this code and take me some suggestion to solve this issue thxx:


#include <QApplication>
#include "mainwindow.h"
#ifndef Q_WS_X11
#include <QtPlugin>
#endif

#ifdef _MSC_VER
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
int argc = 0;
char *argv[1];
#else
int main(int argc, char *argv[])
{
#endif
QApplication a(argc, argv);
MainWindow w;
return a.exec();
}

anda_skoa
21st September 2016, 21:03
Looks like you forgot to post the error.

Cheers,
_

naimatropical
21st September 2016, 21:16
Ups sorry:
this i can solved because it is easy to add ;
error: C2146: syntax error : missing ';' before identifier 'WinMain'

this i dont know how
error: C2061: syntax error : identifier 'LPSTR'
warning: C4007: 'WinMain' : must be '__stdcall'
error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int

d_stranz
21st September 2016, 22:10
Why are you mixing up a Windows API WinMain() entry point with a Qt main() entry point? If you are writing a Qt app, all you need is main() and it will compile and run anywhere:



#include <QApplication>
#include "mainwindow.h"

// I have no idea why you are doing this. Are you blindly copying an example
// from somewhere without having any idea what you are doing? You aren't
// using plugins anywhere in this code.
#ifndef Q_WS_X11
#include <QtPlugin>
#endif

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
return a.exec();
}

ChrisW67
21st September 2016, 22:40
Putting a ; before WinMain kills the first compile error but the code no longer means the same thing.

All of these compile errors arise because the relevant Win32 API headers have not been included.


#include <windows.h>

Fixing those will not make the code make much more sense though. Even your "fake" argc/argv is likely to cause a crash because they are incorrect/uninitialised.