Results 1 to 5 of 5

Thread: WinApi tool with qt

  1. #1

    Default WinApi tool with qt

    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();
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WinApi tool with qt

    Looks like you forgot to post the error.

    Cheers,
    _

  3. #3

    Default Re: WinApi tool with qt

    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

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: WinApi tool with qt

    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:

    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. // I have no idea why you are doing this. Are you blindly copying an example
    5. // from somewhere without having any idea what you are doing? You aren't
    6. // using plugins anywhere in this code.
    7. #ifndef Q_WS_X11
    8. #include <QtPlugin>
    9. #endif
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QApplication a(argc, argv);
    14. MainWindow w;
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: WinApi tool with qt

    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.
    Qt Code:
    1. #include <windows.h>
    To copy to clipboard, switch view to plain text mode 
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.